fix broken chore gone
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user