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++) { blocks.push({
const stitchColorIndex = pesData.stitches[i][3]; colorIndex: penBlock.colorIndex,
threadHex: thread?.hex || "#000000",
// When color changes, save the previous block threadCatalogNumber: thread?.catalogNumber ?? null,
if ( threadBrand: thread?.brand ?? null,
stitchColorIndex !== currentColorIndex || threadDescription: thread?.description ?? null,
i === pesData.stitches.length - 1 threadChart: thread?.chart ?? null,
) { startStitch: penBlock.startStitchIndex,
const endStitch = i === pesData.stitches.length - 1 ? i + 1 : i; endStitch: penBlock.endStitchIndex,
const thread = pesData.threads[currentColorIndex]; stitchCount: penBlock.endStitchIndex - penBlock.startStitchIndex,
blocks.push({ });
colorIndex: currentColorIndex,
threadHex: thread?.hex || "#000000",
threadCatalogNumber: thread?.catalogNumber ?? null,
threadBrand: thread?.brand ?? null,
threadDescription: thread?.description ?? null,
threadChart: thread?.chart ?? null,
startStitch: blockStartStitch,
endStitch: endStitch,
stitchCount: endStitch - blockStartStitch,
});
currentColorIndex = stitchColorIndex;
blockStartStitch = i;
}
} }
return blocks; return blocks;