From aa3c29b6e654a98f17f233110c497fbfc699c7bd Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 06:03:40 +0000 Subject: [PATCH] Group recently bought by section, like the list The recently bought chips now sit under the same section headings as the items still to buy, in aisle order. The heading is a SectionHeading component shared by both, and both use bySection. --- web/src/components/ListScreen.svelte | 50 +++++++++++++----------- web/src/components/SectionHeading.svelte | 27 +++++++++++++ 2 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 web/src/components/SectionHeading.svelte diff --git a/web/src/components/ListScreen.svelte b/web/src/components/ListScreen.svelte index a981b31..8436ed0 100644 --- a/web/src/components/ListScreen.svelte +++ b/web/src/components/ListScreen.svelte @@ -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'; @@ -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); @@ -274,20 +280,8 @@ {/if} {#each groups as group (group.section?.key ?? 'other')} - {@const label = sectionLabel(group.section, catalogue.lang) || t('list.other')}
-

- - -

+
    {#each group.items as item (item.id)} (editing = item)} {trip} /> @@ -316,16 +310,26 @@

    {t('list.recent')}

    {t('list.recent.hint')}

    -
      - {#each recent as item (item.id)} -
    • - -
    • +
      + {#each recentGroups as group (group.section?.key ?? 'other')} +
      + +
        + {#each group.items as item (item.id)} +
      • + +
      • + {/each} +
      +
      {/each} -
    +
    {/if} diff --git a/web/src/components/SectionHeading.svelte b/web/src/components/SectionHeading.svelte new file mode 100644 index 0000000..7c73048 --- /dev/null +++ b/web/src/components/SectionHeading.svelte @@ -0,0 +1,27 @@ + + +

    + +