fix: Use decoded penStitches for progress monitor color blocks

🤖 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 00:09:14 +01:00
parent 9f13d49487
commit 0e504c3069

View file

@ -60,9 +60,9 @@ export function ProgressMonitor() {
? ((sewingProgress?.currentStitch || 0) / patternInfo.totalStitches) * 100 ? ((sewingProgress?.currentStitch || 0) / patternInfo.totalStitches) * 100
: 0; : 0;
// Calculate color block information from pesData // Calculate color block information from decoded penStitches
const colorBlocks = useMemo(() => { const colorBlocks = useMemo(() => {
if (!pesData) return []; if (!pesData || !pesData.penStitches) return [];
const blocks: Array<{ const blocks: Array<{
colorIndex: number; colorIndex: number;
@ -76,34 +76,20 @@ export function ProgressMonitor() {
threadChart: string | null; threadChart: string | null;
}> = []; }> = [];
let currentColorIndex = pesData.stitches[0]?.[3] ?? 0; // Use the pre-computed color blocks from decoded PEN data
let blockStartStitch = 0; for (const penBlock of pesData.penStitches.colorBlocks) {
const thread = pesData.threads[penBlock.colorIndex];
for (let i = 0; i < pesData.stitches.length; i++) {
const stitchColorIndex = pesData.stitches[i][3];
// When color changes, save the previous block
if (
stitchColorIndex !== currentColorIndex ||
i === pesData.stitches.length - 1
) {
const endStitch = i === pesData.stitches.length - 1 ? i + 1 : i;
const thread = pesData.threads[currentColorIndex];
blocks.push({ blocks.push({
colorIndex: currentColorIndex, colorIndex: penBlock.colorIndex,
threadHex: thread?.hex || "#000000", threadHex: thread?.hex || "#000000",
threadCatalogNumber: thread?.catalogNumber ?? null, threadCatalogNumber: thread?.catalogNumber ?? null,
threadBrand: thread?.brand ?? null, threadBrand: thread?.brand ?? null,
threadDescription: thread?.description ?? null, threadDescription: thread?.description ?? null,
threadChart: thread?.chart ?? null, threadChart: thread?.chart ?? null,
startStitch: blockStartStitch, startStitch: penBlock.startStitchIndex,
endStitch: endStitch, endStitch: penBlock.endStitchIndex,
stitchCount: endStitch - blockStartStitch, stitchCount: penBlock.endStitchIndex - penBlock.startStitchIndex,
}); });
currentColorIndex = stitchColorIndex;
blockStartStitch = i;
}
} }
return blocks; return blocks;