Add Select all / Clear all to the lunch screen

This commit is contained in:
iamdoubz committed 2026-11-05 16:47:38 -06:00
1 parent 25ee29bbc5
commit 633f83b1d4
1 file changed
+22 -1
+22 -1
View File
@@ -16,6 +16,24 @@
const child = $derived(kids.find((c) => c.id === childId));
const hasMenu = $derived(app.household!.sources.some((s) => s.layout_type === 'menu' && s.child_ids.includes(childId ?? -1)));
const picked = $derived(days?.filter((d) => d.picked).length ?? 0);
const open = $derived(days?.filter((d) => !d.greyed) ?? []); // days that can be picked
const allPicked = $derived(open.length > 0 && open.every((d) => d.picked));
let bulkBusy = $state(false);
async function pickAll() {
// Select all picks every open day; when they're all picked already, it clears every pick instead.
const dates = allPicked ? days!.filter((d) => d.picked).map((d) => d.date) : open.filter((d) => !d.picked).map((d) => d.date);
if (!dates.length) return;
bulkBusy = true;
try {
days = await api<LunchDay[]>('/lunch/bulk', { method: 'POST', json: { child_id: childId, dates, picked: !allPicked } });
toast(allPicked ? `Cleared ${dates.length} days` : `Picked ${dates.length} days`);
} catch (e: any) {
toast(e.message);
} finally {
bulkBusy = false;
}
}
async function load() {
if (childId === null) return;
@@ -72,7 +90,10 @@
{:else if !days.length}
<p class="empty">No published menu for {monthLabel(month)} yet. Scan it from the Scans tab.</p>
{:else}
<p class="muted">{child?.display_name}: tap the days to pack lunch. {picked} picked. Each pick goes on the calendar as “Pack lunch”.</p>
<div class="row spread">
<p class="muted grow">{child?.display_name}: tap the days to pack lunch. {picked} picked. Each pick goes on the calendar as “Pack lunch”.</p>
<button onclick={pickAll} disabled={bulkBusy || !open.length}>{allPicked ? 'Clear all' : 'Select all'}</button>
</div>
<ul class="days">
{#each days as d (d.date)}
<li class="card day" class:greyed={d.greyed} class:picked={d.picked}>