From 66ed9750e97033dd79594dc26f4ff0f2276f1ba9 Mon Sep 17 00:00:00 2001 From: JCEEE <0xjceee@proton.me> Date: Tue, 22 Sep 2026 20:10:42 +0100 Subject: [PATCH] fix broken chore gone --- .../src/routes/[fam]/[username]/+page.svelte | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/frontend/src/routes/[fam]/[username]/+page.svelte b/frontend/src/routes/[fam]/[username]/+page.svelte index a968d17..bcd928d 100644 --- a/frontend/src/routes/[fam]/[username]/+page.svelte +++ b/frontend/src/routes/[fam]/[username]/+page.svelte @@ -917,30 +917,23 @@ } } catch (e) { // A stale assigned ID (parent re-saved chores while this tab was - // open in the background) leaves the chore untogglable — refresh - // the store so the UI self-heals instead of staying stuck. - try { - await famStore.init(famId); - } catch {} - if (wasCompleted) { - famStore.applyRecord( - 'completions', - { - id: 'revert-' + chore.id + '-' + Date.now(), - famId, - memberId, - assignedChoreId: chore.id, - date: todayChild, - completedAt: new Date().toISOString() - } as Completion, - 'create' - ); - } else { - const optimistic = completions.find((c) => c.id === 'optimistic-' + chore.id); - if (optimistic) { - famStore.applyRecord('completions', optimistic, 'delete'); - } + // open in the background) leaves the chore untogglable. init() is + // a no-op when already initialized, so force a resync() to drop + // the dead card. Never re-add completions for the gone chore — + // that is what kept the error reoccurring after "refresh". + const optimistic = completions.find((c) => c.id === 'optimistic-' + chore.id); + if (optimistic) { + famStore.applyRecord('completions', optimistic, 'delete'); } + try { + await famStore.resync(); + } catch {} + const msg = e instanceof Error ? e.message : String(e); + showToast( + /CHORE_GONE/.test(msg) + ? 'This chore was changed — list refreshed.' + : 'Toggle failed — please try again.' + ); console.error('Toggle failed:', e); } finally { const next = new Set(togglingIds);