Today view: extract selectTodayView projection — table as code#1162
Open
mircealungu wants to merge 1 commit into
Open
Today view: extract selectTodayView projection — table as code#1162mircealungu wants to merge 1 commit into
mircealungu wants to merge 1 commit into
Conversation
…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>
✅ Deploy Preview for voluble-nougat-015dd1 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
(incl. paused waiting lesson) / error / off / empty_today / setup.
🤖 Generated with Claude Code