diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 4d29348..f4a5e4b 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -3,7 +3,6 @@ import { getJSON } from '$lib/api.js'; import * as P from '$lib/prefs.js'; import MoodNav from '$lib/components/MoodNav.svelte'; - import Lane from '$lib/components/Lane.svelte'; import ArticleCard from '$lib/components/ArticleCard.svelte'; import BoundariesPanel from '$lib/components/BoundariesPanel.svelte'; @@ -11,18 +10,25 @@ let selected = $state('today'); let brief = $state(null); let feed = $state([]); - let lanes = $state([]); let userPrefs = $state(P.blank()); let showBoundaries = $state(false); let loading = $state(true); let error = $state(''); let filtersOn = $derived(P.active(userPrefs)); - - const moodByKey = (k) => moods.find((m) => m.key === k); + let current = $derived(moods.find((m) => m.key === selected)); + let viewLabel = $derived(current?.label ?? 'Today'); + let viewSubtitle = $derived( + selected === 'today' + ? brief?.brief_date + ? `Five good things · ${brief.brief_date}` + : 'Five good things today' + : (current?.description ?? '') + ); function feedUrl(moodKey, limit) { - const merged = P.merge(userPrefs, moodByKey(moodKey)?.filter ?? {}); + const mood = moods.find((m) => m.key === moodKey); + const merged = P.merge(userPrefs, mood?.filter ?? {}); const q = P.param(merged); return `/api/feed?limit=${limit}${q ? '&' + q : ''}`; } @@ -31,23 +37,14 @@ return `/api/brief?limit=5${q ? '&' + q : ''}`; } - async function loadToday() { - brief = await getJSON(briefUrl()); - const keys = ['wonder', 'people-helping', 'solutions']; - lanes = await Promise.all( - keys.map(async (k) => ({ ...moodByKey(k), items: (await getJSON(feedUrl(k, 4))).items })) - ); - } - async function loadMood(key) { - feed = (await getJSON(feedUrl(key, 24))).items; - } - async function select(key) { selected = key; error = ''; try { - if (key === 'today') await loadToday(); - else await loadMood(key); + // Today = just the day's highlights. Other moods reveal that category only + // when chosen (categories live behind their selection, not on the home). + if (key === 'today') brief = await getJSON(briefUrl()); + else feed = (await getJSON(feedUrl(key, 24))).items; } catch (e) { error = 'Something went quiet — could not reach the feed.'; } @@ -94,43 +91,39 @@

Gathering the good news…

{:else if error}

{error}

-{:else if selected === 'today'} - {#if brief?.items?.length} -
-

{brief.title ?? 'Five Good Things Today'}

- - {#if brief.items.length > 1} -
- {#each brief.items.slice(1) as a (a.id)} - - {/each} -
- {/if} -
- {:else} -

No brief yet today — try a calmer filter, or check back soon.

- {/if} - - {#each lanes as lane (lane.key)} - select(lane.key)} /> - {/each} - -

✦ that's the good news for today ✦

{:else} -
-

{moodByKey(selected)?.label}

-

{moodByKey(selected)?.description}

- {#if feed.length} -
+ {#key selected} +
+

{viewLabel}

+ {#if viewSubtitle}

{viewSubtitle}

{/if} +
+ + {#if selected === 'today'} + {#if brief?.items?.length} +
+ + {#if brief.items.length > 1} +
+ {#each brief.items.slice(1) as a (a.id)} + + {/each} +
+ {/if} +
+

✦ that's the good news for today ✦

+ {:else} +

No brief yet today — try a calmer filter, or check back soon.

+ {/if} + {:else if feed.length} +
{#each feed as a (a.id)} {/each}
{:else} -

Nothing in this lane right now — try another mood or ease a filter.

+

Nothing in this mood right now — try another, or ease a boundary.

{/if} -
+ {/key} {/if}