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 }, );