fix broken chore gone

This commit is contained in:
JCEEE
2026-09-22 20:10:42 +01:00
parent 0fed19461e
commit 66ed9750e9
@@ -917,30 +917,23 @@
} }
} catch (e) { } catch (e) {
// A stale assigned ID (parent re-saved chores while this tab was // A stale assigned ID (parent re-saved chores while this tab was
// open in the background) leaves the chore untogglable — refresh // open in the background) leaves the chore untogglable. init() is
// the store so the UI self-heals instead of staying stuck. // a no-op when already initialized, so force a resync() to drop
try { // the dead card. Never re-add completions for the gone chore —
await famStore.init(famId); // that is what kept the error reoccurring after "refresh".
} catch {} const optimistic = completions.find((c) => c.id === 'optimistic-' + chore.id);
if (wasCompleted) { if (optimistic) {
famStore.applyRecord( famStore.applyRecord('completions', optimistic, 'delete');
'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');
}
} }
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); console.error('Toggle failed:', e);
} finally { } finally {
const next = new Set(togglingIds); const next = new Set(togglingIds);