Skip to content

Today view: extract selectTodayView projection — table as code#1162

Open
mircealungu wants to merge 1 commit into
masterfrom
wt/today-view-projection
Open

Today view: extract selectTodayView projection — table as code#1162
mircealungu wants to merge 1 commit into
masterfrom
wt/today-view-projection

Conversation

@mircealungu
Copy link
Copy Markdown
Member

Summary

`TodayAudio.js`'s render was a scattered if-cascade (`isLoading` →
`isGenerating` → `lessonData` → `error`/`off`/`active`/`setup` via
let-and-assign locals). Lifts the projection into one pure function that
returns the view as a tagged value:

```js
function selectTodayView({ isLoading, prefLoaded, isGenerating, lessonData, subscription, error }) {
if (isLoading || !prefLoaded) return "loading";
if (isGenerating) return "generating";
if (lessonData) return "today_lesson"; // includes paused waiting lesson
if (error) return "error";
const status = subscription?.subscription_status;
if (status === "off") return "off";
if (status === "active") return "empty_today";
return "setup";
}
```

Render becomes a single dispatch on `view`; the four centered-layout views
(`error`, `off`, `empty_today`, `setup`) share their layout via a small
`CenteredCta` component and a `cta` object literal (one row of copy/action
per view). Behavior unchanged. The "what does the user see in state X?"
question is now answerable by reading one function.

Pairs with api#651 (cron's `decide_generation` — same pattern on the server).

Test plan

  • Build green (`vite build`).
  • All 7 Today views render as before: loading / generating / today_lesson
    (incl. paused waiting lesson) / error / off / empty_today / setup.

🤖 Generated with Claude Code

…w per state

The Today render was an if-cascade scattered across ~200 lines: isLoading,
isGenerating, lessonData, then error/off/active/setup nested as let-and-assign
locals. Lifting it into a pure selectTodayView({...}) that returns one of
"loading | generating | today_lesson | error | off | empty_today | setup" puts
the projection table directly in the file — one return per row of the table.
The render is now a single early-return switch on `view`; the four
centered-layout views share copy via a `cta` object literal and a small
CenteredCta component. Behavior unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 5, 2026

Deploy Preview for voluble-nougat-015dd1 ready!

Name Link
🔨 Latest commit 54d2344
🔍 Latest deploy log https://app.netlify.com/projects/voluble-nougat-015dd1/deploys/6a22f5e0db4d4a0008acae84
😎 Deploy Preview https://deploy-preview-1162--voluble-nougat-015dd1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant