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.
This commit is contained in:
2026-09-25 21:16:47 -07:00
parent 83b58c23a3
commit b4832dbf09
+10 -3
View File
@@ -48,7 +48,6 @@
$: figTags = (taxonomy?.tags ?? []).filter((t) => t.slug.startsWith('fig-') || t.name.startsWith('fig-')); $: 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-')); $: featTags = (taxonomy?.tags ?? []).filter((t) => t.slug.startsWith('feat-') || t.name.startsWith('feat-'));
$: speciesName = (id: number | null) => categories.find((c) => c.id === id)?.name ?? ''; $: speciesName = (id: number | null) => categories.find((c) => c.id === id)?.name ?? '';
$: figureName = figureTerms.find((t) => t.id === (figIds[0] ?? null))?.name ?? null;
// ── Draft fields ── // ── Draft fields ──
let sku = slab.sku || ''; let sku = slab.sku || '';
@@ -74,17 +73,25 @@
$: edgeName = edgeTerms.find((t) => t.id === edgeId)?.name ?? null; $: edgeName = edgeTerms.find((t) => t.id === edgeId)?.name ?? null;
$: primaryLeaf = categories.find((c) => c.id === primaryCatId); $: 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() { function regenerateCopy() {
if (!primaryLeaf || !speciesName(speciesId as number)) return; if (!primaryLeaf || !speciesName(speciesId as number)) return;
const figure = currentFigureName();
title = buildTitle( title = buildTitle(
{ lengthIn: slab.lengthIn, widthAvgIn: slab.widthAvgIn, thicknessIn: slab.thicknessIn, bdft: slab.bdft, edgeName }, { lengthIn: slab.lengthIn, widthAvgIn: slab.widthAvgIn, thicknessIn: slab.thicknessIn, bdft: slab.bdft, edgeName },
figureName, figure,
speciesName(speciesId as number), speciesName(speciesId as number),
{ slug: primaryLeaf.slug, name: primaryLeaf.name }, { slug: primaryLeaf.slug, name: primaryLeaf.name },
); );
shortDesc = buildShortDescription( shortDesc = buildShortDescription(
{ lengthIn: slab.lengthIn, widthAvgIn: slab.widthAvgIn, thicknessIn: slab.thicknessIn, bdft: slab.bdft, edgeName }, { lengthIn: slab.lengthIn, widthAvgIn: slab.widthAvgIn, thicknessIn: slab.thicknessIn, bdft: slab.bdft, edgeName },
figureName, figure,
speciesName(speciesId as number), speciesName(speciesId as number),
{ slug: primaryLeaf.slug, name: primaryLeaf.name }, { slug: primaryLeaf.slug, name: primaryLeaf.name },
); );