From b4832dbf0991d7841051362e2062d44cad393024 Mon Sep 17 00:00:00 2001 From: Ty Balascio Date: Fri, 25 Sep 2026 21:16:47 -0700 Subject: [PATCH] fix(fe): build the title from the live figure selection regenerateCopy() runs synchronously from a click handler, but it read the figureName reactive, which Svelte has not flushed yet in that tick - so a figure picked in the form never reached the title. Resolve the figure straight from figIds at call time instead. --- frontend/src/review/ReviewForm.svelte | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/review/ReviewForm.svelte b/frontend/src/review/ReviewForm.svelte index 76b7224..1be0534 100644 --- a/frontend/src/review/ReviewForm.svelte +++ b/frontend/src/review/ReviewForm.svelte @@ -48,7 +48,6 @@ $: figTags = (taxonomy?.tags ?? []).filter((t) => t.slug.startsWith('fig-') || t.name.startsWith('fig-')); $: featTags = (taxonomy?.tags ?? []).filter((t) => t.slug.startsWith('feat-') || t.name.startsWith('feat-')); $: speciesName = (id: number | null) => categories.find((c) => c.id === id)?.name ?? ''; - $: figureName = figureTerms.find((t) => t.id === (figIds[0] ?? null))?.name ?? null; // ── Draft fields ── let sku = slab.sku || ''; @@ -74,17 +73,25 @@ $: edgeName = edgeTerms.find((t) => t.id === edgeId)?.name ?? null; $: primaryLeaf = categories.find((c) => c.id === primaryCatId); + // Read the figure from the live selection, not the `figureName` reactive: + // this runs synchronously from a click handler, before Svelte flushes the + // reactive update, so the reactive would still hold the previous value. + function currentFigureName(): string | null { + return figureTerms.find((t) => t.id === (figIds[0] ?? null))?.name ?? null; + } + function regenerateCopy() { if (!primaryLeaf || !speciesName(speciesId as number)) return; + const figure = currentFigureName(); title = buildTitle( { lengthIn: slab.lengthIn, widthAvgIn: slab.widthAvgIn, thicknessIn: slab.thicknessIn, bdft: slab.bdft, edgeName }, - figureName, + figure, speciesName(speciesId as number), { slug: primaryLeaf.slug, name: primaryLeaf.name }, ); shortDesc = buildShortDescription( { lengthIn: slab.lengthIn, widthAvgIn: slab.widthAvgIn, thicknessIn: slab.thicknessIn, bdft: slab.bdft, edgeName }, - figureName, + figure, speciesName(speciesId as number), { slug: primaryLeaf.slug, name: primaryLeaf.name }, );