Switch between menu readings in review and fix menus after publishing
This commit is contained in:
1 parent
98ef76bc1e
commit
4268e17dea
5 files changed
+112
-35
No files matched your search
@@ -25,7 +25,9 @@ export interface CalEvent {
|
||||
export interface MenuItem {
|
||||
id: number; scan_id: number; source_id: number; date: string; items: string[]; no_lunch: boolean;
|
||||
page: number | null; cell_bbox: number[] | null; flags: string[]; source_name?: string;
|
||||
reads: MenuRead[] | null; // both readings, when a double read disagreed
|
||||
}
|
||||
export interface MenuRead { items: string[]; no_lunch: boolean }
|
||||
export interface Scan {
|
||||
id: number; source_id: number; source_name: string; layout_type: Source['layout_type']; hint_month: string;
|
||||
date_start: string | null; date_end: string | null; image_keys: string[];
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<script lang="ts">
|
||||
import Check from '@lucide/svelte/icons/check';
|
||||
import TriangleAlert from '@lucide/svelte/icons/triangle-alert';
|
||||
import { untrack } from 'svelte';
|
||||
import type { MenuItem, MenuRead } from '../lib/api';
|
||||
import { dayLabel } from '../lib/dates';
|
||||
|
||||
let { item, onsave }: { item: MenuItem; onsave: (items: string[], noLunch: boolean) => Promise<void> } = $props();
|
||||
|
||||
// The form edits its own copy; picking a reading replaces the copy with that reading.
|
||||
let text = $state(untrack(() => item.items.join('\n')));
|
||||
let noLunch = $state(untrack(() => item.no_lunch));
|
||||
let saving = $state(false);
|
||||
const lines = $derived(text.split('\n').map((s) => s.trim()).filter(Boolean));
|
||||
const shows = (r: MenuRead) => r.no_lunch === noLunch && r.items.join('\n') === lines.join('\n');
|
||||
|
||||
function pick(r: MenuRead) {
|
||||
text = r.items.join('\n');
|
||||
noLunch = r.no_lunch;
|
||||
}
|
||||
|
||||
async function submit(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
saving = true;
|
||||
try {
|
||||
await onsave(lines, noLunch);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<li class="card day">
|
||||
<form class="stack" onsubmit={submit}>
|
||||
<div class="row spread">
|
||||
<span class="strong">{dayLabel(item.date)}</span>
|
||||
{#each item.flags as flag}<span class="badge warn"><TriangleAlert size={12} aria-hidden="true" />{flag}</span>{/each}
|
||||
</div>
|
||||
{#if item.reads}
|
||||
<!-- The double read disagreed: both readings are kept, so you can compare them before saving. -->
|
||||
<div class="reads" role="group" aria-label={`Readings of ${dayLabel(item.date)}`}>
|
||||
{#each item.reads as r, i}
|
||||
<button type="button" class="sm" aria-pressed={shows(r)} onclick={() => pick(r)}>
|
||||
{#if shows(r)}<Check size={16} aria-hidden="true" />{/if}Read {i + 1}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<textarea bind:value={text} aria-label={`Menu for ${dayLabel(item.date)}`} rows={Math.max(2, lines.length)}></textarea>
|
||||
<div class="row spread">
|
||||
<label class="check small"><input type="checkbox" bind:checked={noLunch} /> No lunch this day</label>
|
||||
<button class="sm" type="submit" disabled={saving}>Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
|
||||
<style>
|
||||
textarea { min-height: 72px; }
|
||||
.reads { display: flex; gap: var(--s2); }
|
||||
.reads button { flex: 1; }
|
||||
</style>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script lang="ts">
|
||||
import Utensils from '@lucide/svelte/icons/utensils';
|
||||
import { api, type MenuItem, type Scan } from '../lib/api';
|
||||
import { toast } from '../lib/state.svelte';
|
||||
import { dayLabel } from '../lib/dates';
|
||||
import MenuDay from './MenuDay.svelte';
|
||||
|
||||
// A scan's menu days, editable in review and after publishing.
|
||||
let { scan = $bindable() }: { scan: Scan } = $props();
|
||||
const flagged = $derived(scan.menu_items.filter((m) => m.flags.length).length);
|
||||
const published = $derived(scan.status === 'published');
|
||||
|
||||
async function save(m: MenuItem, items: string[], noLunch: boolean) {
|
||||
try {
|
||||
await api(`/menu_items/${m.id}`, { method: 'PATCH', json: { items, no_lunch: noLunch } });
|
||||
scan = await api<Scan>(`/scans/${scan.id}`);
|
||||
toast(`Saved ${dayLabel(m.date)}`);
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="section">
|
||||
<h2 class="section-title">
|
||||
<Utensils size={16} aria-hidden="true" />{published ? 'Fix the menu' : 'Menu'}
|
||||
<span class="count">{scan.menu_items.length} days{flagged ? `, ${flagged} need a look` : ''}</span>
|
||||
</h2>
|
||||
<p class="hint">
|
||||
One food per line.
|
||||
{published ? 'Changes show on the Lunch tab as soon as you save.' : 'Your kids pick lunch days on the Lunch tab after you publish.'}
|
||||
</p>
|
||||
<ul class="days">
|
||||
{#each scan.menu_items as m (m.id)}
|
||||
<MenuDay item={m} onsave={(items, noLunch) => save(m, items, noLunch)} />
|
||||
{/each}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.days { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
|
||||
</style>
|
||||
@@ -13,17 +13,17 @@
|
||||
import Sparkles from '@lucide/svelte/icons/sparkles';
|
||||
import TriangleAlert from '@lucide/svelte/icons/triangle-alert';
|
||||
import Undo2 from '@lucide/svelte/icons/undo-2';
|
||||
import Utensils from '@lucide/svelte/icons/utensils';
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import ZoomIn from '@lucide/svelte/icons/zoom-in';
|
||||
import ZoomOut from '@lucide/svelte/icons/zoom-out';
|
||||
import type { Component } from 'svelte';
|
||||
import { api, KINDS, type CalEvent, type EventValues as Values, type Kind, type MenuItem, type Scan } from '../lib/api';
|
||||
import { api, KINDS, type CalEvent, type EventValues as Values, type Kind, type Scan } from '../lib/api';
|
||||
import { app, toast } from '../lib/state.svelte';
|
||||
import { dayLabel, monthsBetween, whenLabel } from '../lib/dates';
|
||||
import { monthsBetween, whenLabel } from '../lib/dates';
|
||||
import { KIND_ICONS } from '../lib/icons';
|
||||
import Segmented from '../lib/ui/Segmented.svelte';
|
||||
import EventEditor from './EventEditor.svelte';
|
||||
import MenuDays from './MenuDays.svelte';
|
||||
import MonthGrid from './MonthGrid.svelte';
|
||||
|
||||
let { scan = $bindable() }: { scan: Scan } = $props();
|
||||
@@ -59,7 +59,6 @@
|
||||
);
|
||||
const children = $derived(new Map(app.household!.children.map((c) => [c.id, c])));
|
||||
const colorFor = (e: CalEvent) => children.get(e.child_ids[0])?.color ?? 'var(--primary)';
|
||||
const flaggedMenu = $derived(scan.menu_items.filter((m) => m.flags.length).length);
|
||||
|
||||
async function refresh() {
|
||||
scan = await api<Scan>(`/scans/${scan.id}`);
|
||||
@@ -113,12 +112,6 @@
|
||||
view = 'list';
|
||||
}
|
||||
|
||||
async function saveMenu(m: MenuItem, text: string, noLunch: boolean) {
|
||||
const items = text.split('\n').map((s) => s.trim()).filter(Boolean);
|
||||
await run(() => api(`/menu_items/${m.id}`, { method: 'PATCH', json: { items, no_lunch: noLunch } }));
|
||||
toast(`Saved ${dayLabel(m.date)}`);
|
||||
}
|
||||
|
||||
async function publish() {
|
||||
busy = true;
|
||||
try {
|
||||
@@ -289,29 +282,7 @@
|
||||
{@render collapsed('unchanged', 'Unchanged', CheckCheck, unchanged)}
|
||||
{@render collapsed('excluded', 'Not for this child, or unchecked', EyeOff, excluded)}
|
||||
|
||||
{#if scan.menu_items.length}
|
||||
<section class="section">
|
||||
<h2 class="section-title"><Utensils size={16} aria-hidden="true" />Menu <span class="count">{scan.menu_items.length} days{flaggedMenu ? `, ${flaggedMenu} need a look` : ''}</span></h2>
|
||||
<p class="hint">One food per line. Your kids pick lunch days on the Lunch tab after you publish.</p>
|
||||
<ul class="menu-days">
|
||||
{#each scan.menu_items as m (m.id)}
|
||||
<li class="card menu-day">
|
||||
<form class="stack" onsubmit={(ev) => { ev.preventDefault(); const fd = new FormData(ev.currentTarget as HTMLFormElement); saveMenu(m, String(fd.get('items') ?? ''), fd.get('no_lunch') === 'on'); }}>
|
||||
<div class="row spread">
|
||||
<span class="strong">{dayLabel(m.date)}</span>
|
||||
{#each m.flags as flag}<span class="badge warn"><TriangleAlert size={12} aria-hidden="true" />{flag}</span>{/each}
|
||||
</div>
|
||||
<textarea name="items" aria-label={`Menu for ${dayLabel(m.date)}`} rows={Math.max(2, m.items.length)}>{m.items.join('\n')}</textarea>
|
||||
<div class="row spread">
|
||||
<label class="check small"><input type="checkbox" name="no_lunch" checked={m.no_lunch} /> No lunch this day</label>
|
||||
<button class="sm" type="submit">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</section>
|
||||
{/if}
|
||||
{#if scan.menu_items.length}<MenuDays bind:scan />{/if}
|
||||
{/if}
|
||||
|
||||
<div class="publish-bar">
|
||||
@@ -380,8 +351,6 @@
|
||||
.disclosure :global(.chev) { transition: transform var(--dur) var(--ease); transform: rotate(-90deg); }
|
||||
.disclosure[aria-expanded='true'] :global(.chev) { transform: none; }
|
||||
|
||||
.menu-days { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
|
||||
.menu-day textarea { min-height: 72px; }
|
||||
|
||||
.publish-bar {
|
||||
position: sticky; bottom: calc(var(--nav-h) + var(--s2) + env(safe-area-inset-bottom)); z-index: var(--z-sticky);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
import { monthLabel } from '../lib/dates';
|
||||
import PageHeader from '../lib/ui/PageHeader.svelte';
|
||||
import StatusBadge from './StatusBadge.svelte';
|
||||
import MenuDays from './MenuDays.svelte';
|
||||
import Review from './Review.svelte';
|
||||
|
||||
let { id }: { id: number } = $props();
|
||||
@@ -118,6 +119,7 @@
|
||||
<a class="btn ghost" href="#/calendar"><CalendarDays size={18} aria-hidden="true" /> See the calendar</a>
|
||||
</div>
|
||||
</section>
|
||||
{#if scan.menu_items.length}<div class="menu-fix"><MenuDays bind:scan /></div>{/if}
|
||||
{:else}
|
||||
<Review bind:scan />
|
||||
<div class="discard">
|
||||
@@ -139,5 +141,6 @@
|
||||
.state-icon.danger { background: var(--danger-soft); color: var(--danger); }
|
||||
.state p { max-width: 48ch; }
|
||||
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s2); margin-top: var(--s2); }
|
||||
.menu-fix { margin-top: var(--s6); }
|
||||
.discard { margin-top: var(--s6); padding-top: var(--s4); border-top: 1px solid var(--border); display: flex; gap: var(--s2); }
|
||||
</style>
|
||||
Reference in new issue
Block a user