fix: Fall back to PEN stitch count when machine reports 0 total stitches

When the machine reports 0 total stitches in patternInfo, fall back to
using the PEN data stitch count (penStitches.stitches.length) for UI
display. This ensures progress percentage and stitch counts display
correctly even when the machine hasn't fully initialized pattern info.

Updated ProgressMonitor to use derived totalStitches value that prefers
patternInfo.totalStitches but falls back to PEN data when needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Henrik Bruhn 2025-12-17 12:14:41 +01:00
parent 467eb9df95
commit f2d05c2714

View file

@ -56,8 +56,15 @@ export function ProgressMonitor() {
const stateVisual = getStateVisualInfo(machineStatus); const stateVisual = getStateVisualInfo(machineStatus);
const progressPercent = patternInfo // Use PEN stitch count as fallback when machine reports 0 total stitches
? ((sewingProgress?.currentStitch || 0) / patternInfo.totalStitches) * 100 const totalStitches = patternInfo
? (patternInfo.totalStitches === 0 && pesData?.penStitches
? pesData.penStitches.stitches.length
: patternInfo.totalStitches)
: 0;
const progressPercent = totalStitches > 0
? ((sewingProgress?.currentStitch || 0) / totalStitches) * 100
: 0; : 0;
// Calculate color block information from decoded penStitches // Calculate color block information from decoded penStitches
@ -173,7 +180,7 @@ export function ProgressMonitor() {
Total Stitches Total Stitches
</span> </span>
<span className="font-semibold text-gray-900 dark:text-gray-100"> <span className="font-semibold text-gray-900 dark:text-gray-100">
{patternInfo.totalStitches.toLocaleString()} {totalStitches.toLocaleString()}
</span> </span>
</div> </div>
<div className="bg-gray-50 dark:bg-gray-700/50 p-2 rounded"> <div className="bg-gray-50 dark:bg-gray-700/50 p-2 rounded">
@ -213,7 +220,7 @@ export function ProgressMonitor() {
</span> </span>
<span className="font-semibold text-gray-900 dark:text-gray-100"> <span className="font-semibold text-gray-900 dark:text-gray-100">
{sewingProgress.currentStitch.toLocaleString()} /{" "} {sewingProgress.currentStitch.toLocaleString()} /{" "}
{patternInfo?.totalStitches.toLocaleString() || 0} {totalStitches.toLocaleString()}
</span> </span>
</div> </div>
<div className="bg-gray-50 dark:bg-gray-700/50 p-2 rounded"> <div className="bg-gray-50 dark:bg-gray-700/50 p-2 rounded">