add toggle fix and possible log out issue
This commit is contained in:
@@ -174,13 +174,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Goals completed feed for the admin overview — every materialized bonus
|
||||
// reward (prize / points / cash), newest first. Undoing the underlying
|
||||
// chore/points deletes the unclaimed reward server-side, so this list
|
||||
// shrinks again in realtime via famStore.
|
||||
let parentGoalsCompleted = $derived.by(() =>
|
||||
parentRewards
|
||||
.filter((r: any) => r.bonusConfigId)
|
||||
// Goals completed feed for the admin overview — this week's materialized
|
||||
// bonus rewards (prize / points / cash), newest first. Undoing the
|
||||
// underlying chore/points deletes the unclaimed reward server-side, so
|
||||
// this list shrinks again in realtime via famStore.
|
||||
let parentGoalsCompleted = $derived.by(() => {
|
||||
const ws = (summary?.weekStart as string) || today;
|
||||
return parentRewards
|
||||
.filter((r: any) => r.bonusConfigId && (r.date || '').slice(0, 10) >= ws)
|
||||
.map((r: any) => {
|
||||
const cfg = parentBonusConfigs.find((c: any) => c.id === r.bonusConfigId);
|
||||
const m = parentMembers.find((x: any) => x.id === r.memberId);
|
||||
@@ -199,8 +200,8 @@
|
||||
};
|
||||
})
|
||||
.sort((a: any, b: any) => (b.date || '').localeCompare(a.date || ''))
|
||||
.slice(0, 10)
|
||||
);
|
||||
.slice(0, 10);
|
||||
});
|
||||
|
||||
// ─── Child View (kanban) ───
|
||||
let memberId = $state(data.memberId || '');
|
||||
@@ -242,7 +243,7 @@
|
||||
|
||||
let claimError = $state('');
|
||||
let todayChild = $derived(todayInTz(famTz));
|
||||
let togglingIds = $state<string>('');
|
||||
let togglingIds = $state<Set<string>>(new Set());
|
||||
|
||||
// ─── Payday countdown (child view) ───
|
||||
let nowMs = $state(Date.now());
|
||||
@@ -622,6 +623,12 @@
|
||||
const rDate = (existingReward?.date || '').slice(0, 10);
|
||||
const rewardInWeek = !!rDate && rDate >= weekStart && rDate <= weekEnd;
|
||||
const rewardOutstanding = !!existingReward && existingReward.status !== 'claimed';
|
||||
// A claimed reward from a previous week with no fresh progress
|
||||
// means the goal is done — drop the card entirely instead of
|
||||
// showing a stale 0% chase.
|
||||
const staleClaimed =
|
||||
!!existingReward && !rewardInWeek && !rewardOutstanding && current === 0;
|
||||
if (staleClaimed) return null;
|
||||
const achieved = existingReward
|
||||
? rewardInWeek || rewardOutstanding
|
||||
: isPercent
|
||||
@@ -652,7 +659,8 @@
|
||||
periodStart: pStart,
|
||||
periodEnd: pEnd
|
||||
};
|
||||
});
|
||||
})
|
||||
.filter((g) => g !== null);
|
||||
});
|
||||
|
||||
// ─── Goal celebrations (bonus rewards achieved) ───
|
||||
@@ -823,8 +831,8 @@
|
||||
async function toggle(chore: AssignedChore) {
|
||||
if (accessDisabled) return;
|
||||
if (chore.isTodo && isTodoExpired(chore)) return;
|
||||
if (togglingIds) return;
|
||||
togglingIds = chore.id;
|
||||
if (togglingIds.has(chore.id)) return;
|
||||
togglingIds = new Set(togglingIds).add(chore.id);
|
||||
|
||||
const wasCompleted = chore.isTodo ? isTodoDone(chore.id) : isCompleted(chore.id, todayChild);
|
||||
if (wasCompleted) {
|
||||
@@ -875,7 +883,9 @@
|
||||
}
|
||||
console.error('Toggle failed:', e);
|
||||
} finally {
|
||||
togglingIds = '';
|
||||
const next = new Set(togglingIds);
|
||||
next.delete(chore.id);
|
||||
togglingIds = next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1492,7 +1502,7 @@
|
||||
<p class="empty">All done!</p>
|
||||
{:else}
|
||||
{#each dailyPending as chore}
|
||||
<button class="chore" onclick={() => toggle(chore)} disabled={!!togglingIds}>
|
||||
<button class="chore" onclick={() => toggle(chore)} disabled={togglingIds.has(chore.id)}>
|
||||
<span class="checkbox">{@html circleIcon}</span>
|
||||
<span class="chore-name">{choreName(chore)}</span>
|
||||
<span class="chore-value">{chore.value} {chore.type}</span>
|
||||
@@ -1509,7 +1519,7 @@
|
||||
<p class="empty">All done!</p>
|
||||
{:else}
|
||||
{#each weeklyPending as chore}
|
||||
<button class="chore" onclick={() => toggle(chore)} disabled={!!togglingIds}>
|
||||
<button class="chore" onclick={() => toggle(chore)} disabled={togglingIds.has(chore.id)}>
|
||||
<span class="checkbox">{@html circleIcon}</span>
|
||||
<span class="chore-name">{choreName(chore)}</span>
|
||||
<span class="chore-value">{chore.value} {chore.type}</span>
|
||||
@@ -1528,7 +1538,7 @@
|
||||
class:todo-black={urgency === 'black'}
|
||||
class:todo-expired={expired}
|
||||
onclick={() => toggle(todo)}
|
||||
disabled={!!togglingIds || expired}
|
||||
disabled={togglingIds.has(todo.id) || expired}
|
||||
>
|
||||
<span class="checkbox">{@html circleIcon}</span>
|
||||
<span class="todo-main">
|
||||
@@ -1556,7 +1566,7 @@
|
||||
class:todo-black={urgency === 'black'}
|
||||
class:todo-expired={expired}
|
||||
onclick={() => toggle(todo)}
|
||||
disabled={!!togglingIds || expired}
|
||||
disabled={togglingIds.has(todo.id) || expired}
|
||||
>
|
||||
<span class="checkbox">{@html circleIcon}</span>
|
||||
<span class="todo-main">
|
||||
@@ -1590,7 +1600,7 @@
|
||||
{#each completedToday as c}
|
||||
{@const chore = assigned.find((a) => a.id === c.assignedChoreId)}
|
||||
{#if chore}
|
||||
<button class="chore done" onclick={() => toggle(chore)} disabled={!!togglingIds}>
|
||||
<button class="chore done" onclick={() => toggle(chore)} disabled={togglingIds.has(chore.id)}>
|
||||
<span class="checkbox">{@html checkCircleIcon}</span>
|
||||
<span class="chore-name">{choreName(chore)}</span>
|
||||
{#if chore.type === 'emoji'}
|
||||
|
||||
Reference in New Issue
Block a user