From f2d05c2714f18697d124d927a5539a70d48c33c7 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Wed, 17 Dec 2025 12:14:41 +0100 Subject: [PATCH] fix: Fall back to PEN stitch count when machine reports 0 total stitches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/components/ProgressMonitor.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/ProgressMonitor.tsx b/src/components/ProgressMonitor.tsx index 0f1d3ea..a952328 100644 --- a/src/components/ProgressMonitor.tsx +++ b/src/components/ProgressMonitor.tsx @@ -56,8 +56,15 @@ export function ProgressMonitor() { const stateVisual = getStateVisualInfo(machineStatus); - const progressPercent = patternInfo - ? ((sewingProgress?.currentStitch || 0) / patternInfo.totalStitches) * 100 + // Use PEN stitch count as fallback when machine reports 0 total stitches + 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; // Calculate color block information from decoded penStitches @@ -173,7 +180,7 @@ export function ProgressMonitor() { Total Stitches - {patternInfo.totalStitches.toLocaleString()} + {totalStitches.toLocaleString()}
@@ -213,7 +220,7 @@ export function ProgressMonitor() { {sewingProgress.currentStitch.toLocaleString()} /{" "} - {patternInfo?.totalStitches.toLocaleString() || 0} + {totalStitches.toLocaleString()}