Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions web/src/components/ListScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import ItemRow from './ItemRow.svelte';
import ItemSheet from './ItemSheet.svelte';
import TripBar from './TripBar.svelte';
import SectionHeading from './SectionHeading.svelte';
import SectionSheet from './SectionSheet.svelte';
import Thumb from './Thumb.svelte';
import ListPicker from './ListPicker.svelte';
Expand All @@ -34,13 +35,18 @@
// the section whose icon is being picked; null for Other
let iconFor = $state<{ section: Section | undefined } | null>(null);
let input: HTMLInputElement;
const pickIcon = (section: Section | undefined) => (iconFor = { section });

const open = $derived(toBuy(items.items));
const trip = $derived(trips.current);
const groups = $derived(bySection(open, catalogue.kindSections, (i) => choices.sectionOf(i)));
// both the list and what was bought are grouped by section, in aisle order
const inSections = (list: Item[]) =>
bySection(list, catalogue.kindSections, (i) => choices.sectionOf(i));
const groups = $derived(inSections(open));
// products, barcodes and usual brands are for groceries
const groceries = $derived(household.kind === GROCERIES);
const recent = $derived(recentlyBought(items.items));
const recentGroups = $derived(inSections(recent));
// "milk, bread, eggs" or a pasted list is several items
const entries = $derived(splitEntries(text));
const many = $derived(entries.length > 1);
Expand Down Expand Up @@ -274,20 +280,8 @@
{/if}

{#each groups as group (group.section?.key ?? 'other')}
{@const label = sectionLabel(group.section, catalogue.lang) || t('list.other')}
<section>
<h2 class="mb-1.5 px-1">
<!-- a tap picks another icon for the section -->
<button
class="-mx-1 flex items-center gap-1.5 rounded-lg px-1 py-0.5 text-xs font-semibold tracking-wide text-zinc-500 uppercase hover:bg-zinc-100 dark:text-zinc-400 dark:hover:bg-zinc-900"
onclick={() => (iconFor = { section: group.section })}
aria-label={t('section.change', { name: label })}
>
<Glyph icon={choices.sectionIcon(group.section)} class="size-4 text-sm" />
<!-- in its own language, so Greek capitals lose their accents -->
<span lang={group.section ? catalogue.lang : 'en'}>{label}</span>
</button>
</h2>
<SectionHeading section={group.section} onpick={pickIcon} />
<ul class="card divide-y divide-zinc-100 p-0 dark:divide-zinc-800">
{#each group.items as item (item.id)}
<ItemRow {item} onedit={() => (editing = item)} {trip} />
Expand Down Expand Up @@ -316,16 +310,26 @@
<section class="mt-2">
<h2 class="font-semibold">{t('list.recent')}</h2>
<p class="mb-3 text-sm text-zinc-500 dark:text-zinc-400">{t('list.recent.hint')}</p>
<ul class="flex flex-wrap gap-2">
{#each recent as item (item.id)}
<li>
<button class="chip" onclick={() => items.putBack(item)}>
<Glyph icon={choices.iconOf(item)} class="size-4 text-brand-700 dark:text-brand-400" />
{catalogue.nameOf(item)}</button
>
</li>
<div class="flex flex-col gap-3">
{#each recentGroups as group (group.section?.key ?? 'other')}
<div>
<SectionHeading section={group.section} onpick={pickIcon} />
<ul class="flex flex-wrap gap-2">
{#each group.items as item (item.id)}
<li>
<button class="chip" onclick={() => items.putBack(item)}>
<Glyph
icon={choices.iconOf(item)}
class="size-4 text-brand-700 dark:text-brand-400"
/>
{catalogue.nameOf(item)}</button
>
</li>
{/each}
</ul>
</div>
{/each}
</ul>
</div>
</section>
{/if}

Expand Down
27 changes: 27 additions & 0 deletions web/src/components/SectionHeading.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script lang="ts">
import { sectionLabel, type Section } from '../lib/catalogue';
import { t } from '../lib/i18n';
import { catalogue } from '../lib/stores/catalogue.svelte';
import { choices } from '../lib/stores/choices.svelte';
import Glyph from './Glyph.svelte';

// A section's icon and name over its items; a tap picks another icon for it.
let {
section,
onpick,
}: { section: Section | undefined; onpick: (section: Section | undefined) => void } = $props();

const label = $derived(sectionLabel(section, catalogue.lang) || t('list.other'));
</script>

<h2 class="mb-1.5 px-1">
<button
class="-mx-1 flex items-center gap-1.5 rounded-lg px-1 py-0.5 text-xs font-semibold tracking-wide text-zinc-500 uppercase hover:bg-zinc-100 dark:text-zinc-400 dark:hover:bg-zinc-900"
onclick={() => onpick(section)}
aria-label={t('section.change', { name: label })}
>
<Glyph icon={choices.sectionIcon(section)} class="size-4 text-sm" />
<!-- in its own language, so Greek capitals lose their accents -->
<span lang={section ? catalogue.lang : 'en'}>{label}</span>
</button>
</h2>