Skip to content

fix(calendar): the view switch lights an option a phone cannot render - #337

Merged
sydevs-bot merged 6 commits into
mainfrom
claude/fix-331-calendar-view-switch
Oct 27, 2026
Merged

sydevs-bot merged 6 commits into
mainfrom
claude/fix-331-calendar-view-switch

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • One pure resolver decides which Schedule-X view renders and which switch option lights, so a phone can no longer light Month over a day list.
  • Schedule-X's own isResponsive is off, which retires the silent rewrite that caused it rather than racing it.
  • useCalendarPosition is typed to the three options the switch offers, so the one name it must never hold cannot reach it.

Change outline

Four seams each held their own copy of "which view is this?". They now read one resolver, with the decision nested under it.

 src/lib/shape/calendar.ts
+  resolveCalendarView(stored, isWide) -> { view, option }
+    stored 'list'            → list,         light List      # at either width
+    isWide                   → stored,       light stored
+    else                     → month-agenda, light Month     # month AND week collapse here
+  isCalendarViewOption(value)                # the switch's bare string → one of the three

 CalendarControls                               src/views/CalendarView/CalendarView.tsx
   useIsWideWidget()
-  view = store.view ?? 'month-grid'
+  option = resolveCalendarView(store.view, isWide).option
   label      — month+year, else the date (week: its first day)
   step(dir)  — a month, a week, or a day
   ToggleGroup value
-    <Month> <Week> <List>
+    <Month> {isWide && <Week>} <List>
   selectView(next)
-    if (!next) return
+    if (!isCalendarViewOption(next)) return   # also covers Radix's empty-string deselect
     store.setView(next)                       # what was PICKED, never the resolution
+    controls.setView(resolveCalendarView(next, isWide).view)

 CalendarGrid                                   src/views/CalendarView/CalendarView.tsx
   useNextCalendarApp({
-    views: [monthGrid, week, list]
+    views: [monthGrid, monthAgenda, week, list] # setView validates the name against this
+    isResponsive: false                         # the only path into SX's own rewrite
-    defaultView: store.view ?? 'month-grid'
+    defaultView: resolveCalendarView(store.view, isWide).view
   }, [controls])

 DrawerStack                                    src/views/DrawerStack/DrawerStack.tsx
-  wide = top.kind === 'calendar' && store.view !== 'list'
+  wide = top.kind === 'calendar' && isWide && store.view !== 'list'
     … also gates the settings cog, so a phone in month view had none

Types

The two names were both string, and the header destructured option while renaming it view — the exact mix-up.

 type ResolvedCalendarView = {
-  view: string
-  option: string
+  view: CalendarViewName     # the four registered SX views
+  option: CalendarViewOption # the three the switch offers — month-agenda is absent
 }

 type CalendarPositionState = {
-  view: string | null
-  setView: (view: string) => void
+  view: CalendarViewOption | null
+  setView: (view: CalendarViewOption) => void
 }

month-agenda renders for Month and is never lit, so the type refuses a switch value with no matching item — at the store, which is where an untyped 'month-agenda' used to get in and be resolved to Month silently. Radix's onValueChange hands over a bare string, so isCalendarViewOption is the one runtime boundary.

Preview

Preview pending — no alias exists yet on this branch.

⚠ No later run is promised to fill this in, so this line stays as a disclosure. The Workers preview address is produced by this repo's own CI publish step (wrangler versions upload --preview-alias pr-337), so it has to be read off that step's output rather than derived — the <branch-slug>.sahajatlas.pages.dev form earlier PRs carry is the host #283 withdrew, and guessing a slug is how a reviewer opens the wrong branch.

To see it without waiting, from this branch:

pnpm dev            # then /calendar?map=0 at 390×844 and at 1280×900
pnpm build && pnpm review:embed   # the same, as a real host-page embed

§ Manual verification below carries the measured result at both widths, so the claim is checkable without either.

Test results

  • Lean gate: ✓ .claude/skills/pr-prep/check.sh — lint, typecheck, 1790 unit tests in 151 files
  • Targeted specs: 9 new cases in src/lib/shape/calendar.test.ts — 6 over the stored-view × width mapping in both directions, 3 over the switch-value guard
  • Build: ✓ --full also ran the production build, assert:css, assert:maps and the eager-payload size budget — all within budget (the calendar is a lazy chunk, so the fourth view never reaches it)

Watched the new cases fail first. With the resolver returning the stored view regardless of width — today's behaviour — 4 of the mapping cases go red, naming month-grid against month-agenda. With the guard relaxed to any non-empty string — the behaviour it replaced — both refusal cases go red.

Manual verification

Driven in headless Chromium against the dev server on real SahajCloud data. Reading .sx__view-container's first child class against the lit role="radio" button:

at first paint Month Week List
390×844 month-agenda-wrapper, Month lit month-agenda-wrapper not offered list-wrapper
1280×900 month-grid-wrapper, Month lit month-grid-wrapper week-wrapper list-wrapper

No two offered options share a body at either size. Also confirmed: Week picked at 1280 → resize to 390 renders the month agenda with Month lit and two options → resize back restores Week over week-wrapper; a filter apply on a phone in Month keeps the lit button matching the body; the settings cog renders on a phone in month view; at 1280 each view still labels and pages by its own unit (month+year → next month, a date → next week, a date → next day).

⚠ That table was measured before the adversarial-review round below, which changed no behaviour: the drawer-width expression is proven equivalent to the helper it replaced over every stored name and both widths, and the switch-value guard refuses only values Radix cannot emit.

Worth a human pass on how the month agenda reads on a real phone — that is a judgement a class list cannot make.

Notes for reviewer

  • Step 5 of the ticket's approach is not implemented, because its premise does not hold. It asked for onClickAgendaDate → setDate, on the grounds that onSelectedDateUpdate fires only from the date picker's own change callback. It also fires for an agenda pick: the agenda's setActiveDate writes datePickerState.selectedDate.value, and createDatePickerState runs an effect over that signal which calls listeners.onChange — the same dateSelectionCallback. Measured in the browser: clicking the next agenda day moves the header's date from 2026-10-27 to 2026-10-28 with nothing wired. The callback would have been dead code.
  • An effect driving the crossing was written, then measured as dead and removed. DrawerStack remounts the whole drawer when isWide flips, because vaul's direction is not hot-swappable, and that remounts the grid — so defaultView already answers a resize. Verified by deleting the effect and re-running the 1280→390→1280 pass. defaultView is now the single seam and its comment records what that rests on.
  • A calendarFillsWidget helper was added, then removed in review as a tautology. It returned exactly isWide && stored !== 'list' over every input, and its name said the opposite of what it returned below the crossing, where the bottom sheet does fill the widget. wide is a no-op on direction: 'bottom', so its one effect there is the settings cog.
  • The isResponsive rationale now has one home, docs/rules/i18n-and-state.md. The mechanism moved there — the resize listener the flag registers, the compat-view rewrite it is the only path into, and what dropping isCalendarSmall costs — and the call site keeps the constraint plus a breadcrumb. src/config/store.ts had also kept stating the rule this branch replaced ("A list view needs the regular width").
  • Dismissed, with reasons: deriving the switch's offered options from the resolver and mapping over them — src/config/translations.test.ts finds keys by matching literal t('…'), so a t(LABELS[option]) indirection would make calendar.view_week look dead in both directions; a useResolvedCalendarView() hook — it could serve only the two reactive readers, not the three getState() ones.
  • One dismissal worth your opinion rather than mine. The adversarial read proposed that the top StackEntry declare its own drawer width, so DrawerStack would ask "does the top view want full width?" and know nothing about calendar view names. It still knows one — it compares the stored view against CALENDAR_VIEW_LIST. The coupling is pre-existing and this branch neither grows nor shrinks it. I left it alone as a change to the drawer-layout contract well outside this fix — but if you want it, it is a clean follow-up.
  • No security review: neither securityReview.triggerPattern nor its content pattern matches this diff.
  • docs/embedding.md is deliberately untouched — no parameter, origin, CSP, sizing or URL-shape change. The visible behaviour is in CHANGELOG.md.
Detail

Why isResponsive: false rather than a smaller fix. setScreenSizeCompatibleView (core.js:2442) is reached only from handleWindowResize, which is registered only inside if ($app.config.isResponsive) (core.js:2541) — so the flag closes the only path. The shallower options would have left the mechanism armed and the app racing it: supplying a false isCalendarSmall, or patching hasSmallScreenCompat on the view objects. isCalendarSmall then stays undefined, and its only consumers are SX's own view dropdown and the sx__is-calendar-small class, whose rules all target the header bar globals.css:532 hides — nothing under src/ keys on either.

Why week collapses onto month-agenda and not list. The agenda keeps a chosen day's own hours in view, which is what Week was being read for, and it leaves one answer below the crossing for every non-list view.

Why the store keeps the pick, not the resolution. A stored week has to survive a trip through a phone width and light Week again above the crossing. Storing the resolution would lose it, and would also mean a store write on every crossing.

Why the drawer-width test is an && and not a helper. Above the crossing the resolver returns the stored view, and both views it can return there are full-width. Below it, nothing is. So isWide && stored !== 'list' is not an approximation of the resolver's answer — it is that answer, for any mapping with those two properties. Verified over all 14 stored-name × width pairs, month-agenda, '' and junk included.

Rejected for question 2 of the ticket: registering createViewDay() and mapping Week → Day below the crossing. day renders sx__week-wrapper, so Week and Day are indistinguishable by wrapper class, and a button reading "Week" over a single day needs a new label — translations are CMS-owned, so it would have waited on a sydevs/SahajCloud issue.

Verification method. ?map=0 on the standalone shell, with the API key supplied through .env.local from the environment's existing read-only key (removed afterwards; the tree is clean). Reads are production-read-only.

Closes #331

🤖 Written by the sydevs autonomous loop — see what this is

🤖 Generated with Claude Code

https://claude.ai/code/session_0111UmECXW42ciGRazy4JhDM

Schedule-X rewrites the rendered view by itself below its breakpoint, and emits
no callback when it does. `month-grid` and `week` both declare
`hasSmallScreenCompat: false`, so `setScreenSizeCompatibleView` moved off them at
mount and at each crossing, to the first registered compat view — `list`. The
switch never learned, so a phone lit Month over a day list, and clicking Month
could not change it: the switch's value was already `month-grid`, so Radix read
the click as a deselect.

`isResponsive: false` retires that rewrite outright — the resize listener is
registered only while the flag is on, and it is the only path into it. A pure
resolver in `lib/shape/calendar.ts` is then the one authority: it maps the stored
view and a width class to the view to render and the option to light. Below the
crossing Month and Week both collapse onto a newly registered `month-agenda`,
which keeps a chosen day's own hours in view, and Week is not offered. The store
keeps what the viewer picked, so widening restores it.

`DrawerStack` sizes the calendar drawer from what renders rather than the stored
name, so the month agenda takes the regular width like the list view — and the
settings cog, which the same test hides, returns to a phone in month view.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Sce9tzi3TGe1F7ZNiqtF5
Three findings from the /simplify pass.

`ResolvedCalendarView` widened both fields to `string`, so nothing separated
"a Schedule-X view name" from "a switch option" — and `CalendarControls`
destructured `option` while renaming it `view`, which is the exact mix-up.
Both fields now carry literal unions, and `month-agenda` is deliberately
absent from the option type: it renders FOR Month and is never lit.

`calendarViewIsFullWidth(view)` had one call site and was only ever fed the
resolver's own output, which made `DrawerStack` know that a narrow width
collapses onto `month-agenda`. It becomes `calendarFillsWidget(stored,
isWide)`, resolving internally.

The effect driving `controls.setView` on a width crossing was dead code:
`DrawerStack` remounts the whole drawer when `isWide` flips, because vaul's
`direction` is not hot-swappable, and that remounts the grid with it — so
`defaultView` already answers a resize. Measured in a browser at 1280→390
→1280 with Week picked, with the effect removed: the month agenda renders
below the crossing and Week is restored above it. That leaves `defaultView`
as the single seam, and its comment records what the dependency rests on.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Sce9tzi3TGe1F7ZNiqtF5
CHANGELOG gets the host-facing entry: what a visitor sees below 768px now,
which options the switch offers at which width, and that nothing above it
changes. The guide's Calendar row and the state rule name the resolver and
why `isResponsive` is off; the responsive decision table gains the row,
which is the one entry where the signal decides what a third-party library
can draw rather than how much room to give it.

docs/embedding.md is unchanged on purpose — no parameter, origin, CSP,
sizing or URL-shape change.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Sce9tzi3TGe1F7ZNiqtF5
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5c0e2d7
Status: ✅  Deploy successful!
Preview URL: https://8b242d22.sahajatlas.pages.dev
Branch Preview URL: https://claude-fix-331-calendar-view.sahajatlas.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
sahajatlas-design 5c0e2d7 Oct 27 2026, 01:09 AM

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 27, 2026
@sydevs-bot

sydevs-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 00:57Z address-review · attempt 1 · session · done
  • 00:57Z address-review · attempt 1 · session
  • 00:45Z review-pr · attempt 1 · session · done
  • 00:45Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The root cause is right and the fix is the small one. I re-derived both claims it rests on in the pinned 2.36.0 build and both hold. One resolver beating five copies of "which view is this?" is right, and nothing host-facing moves.

What is oversized is the prose: 62 of the ~120 added lines are comments, and the isResponsive story now has five homes. One is stale — src/config/store.ts:163 still says "A list view needs the regular width", the rule this PR replaced. Below the crossing no view earns the full width, and that fix belongs here.

Findings

  • should-fix — calendarFillsWidget is exactly isWide && stored !== 'list', and its name says the opposite of what it returns on a phone — src/lib/shape/calendar.ts:279.
  • should-fix — the isResponsive rationale has five homes, and store.ts:163 is the stale one — CalendarView.tsx:337.
  • consider — the resolver's output is typed and its input is not, so the store can still hold 'month-agenda' — src/lib/shape/calendar.ts:258.

What was checked

  • core.js: setScreenSizeCompatibleView (2442) has one caller, handleWindowResize (2461), whose mount call and resize listener both sit inside if ($app.config.isResponsive) (2542).
  • Step 5 was rebutted correctly: an agenda day's handleClick calls setActiveDate unconditionally (5921), reaching dateSelectionCallback (5434) via the effect at 3000.
  • <Drawer key={direction}> (DrawerStack:723,833) with direction from isWide alone (:277) — a crossing does remount the grid, so defaultView suffices.
  • The agenda's unbounded event list scrolls, not clips: .sx__view-container is overflow-y: auto.
  • Read whole: calendar.ts, CalendarView.tsx, DrawerStack.tsx, responsive.ts, store.ts, the Drawer variants. Ran the equivalence over all 16 pairs. No preview to open.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/lib/shape/calendar.ts Resolved
Comment thread src/views/CalendarView/CalendarView.tsx Resolved
Comment thread src/lib/shape/calendar.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 27, 2026
`calendarFillsWidget(stored, isWide)` returned exactly
`isWide && stored !== 'list'` — proven over every stored name and both widths,
including `month-agenda`, `''` and junk. Above the crossing the resolver returns
the stored view, and the two it can return there are both full-width; below it,
nothing is. So the helper, its JSDoc and its three cases stood in for one `&&` on
the line `DrawerStack` already had.

The name said the opposite of what it returned, too: below the crossing the
bottom sheet does fill the widget. `wide` is a no-op on `direction: 'bottom'`
(the Drawer atom's compound variant needs `left`), so its one effect there is
whether the settings cog renders.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0111UmECXW42ciGRazy4JhDM
The rationale for turning Schedule-X's own responsiveness off had five homes,
and the diff that added it carried 62 comment lines against ~60 of changed code.
`docs/rules/i18n-and-state.md` is the maintained one, so the mechanism moves
there — the resize listener the flag registers, the compat-view rewrite it is
the only path into, and what dropping `isCalendarSmall` costs. The call site
keeps the constraint and a breadcrumb.

`src/config/store.ts` still stated the rule this branch replaced: "A list view
needs the regular width." The wide panel exists only above the crossing now, so
below it no view takes it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0111UmECXW42ciGRazy4JhDM
The resolver's output was typed and its input was not, so `setView(view: string)`
still accepted `'month-agenda'` — the one name the switch has no item for — and
the resolver turned it into Month silently.

`useCalendarPosition` now holds `CalendarViewOption | null`, and the toggle
group's bare `string` is narrowed by `isCalendarViewOption` at the single place
that writes it. That guard also subsumes the empty-value check Radix needs for a
deselect, so the one runtime boundary is stated once.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0111UmECXW42ciGRazy4JhDM
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Adopted all three adversarial findings, one commit each. No behaviour changed. Lean gate green: 1790 tests in 151 files.

  • calendarFillsWidget is one && — 53ff584. Helper, JSDoc and three cases deleted; equivalence re-verified over all 14 input pairs against the real resolver.
  • five homes for one story — 4016c4e. Mechanism moved to docs/rules/i18n-and-state.md; store.ts:163 no longer states the replaced rule. The isResponsive block is 3 lines, was 11.
  • the resolver's input is untyped — 5c0e2d7. The store holds CalendarViewOption | null, and isCalendarViewOption narrows Radix's bare string at the one writer.

Branch was already current with main, so no merge commit. Body refreshed: outline, types, test count, and that the browser table predates this round.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 27, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 27, 2026 01:13
@sydevs-bot
sydevs-bot requested a review from Ardnived October 27, 2026 01:13
@sydevs-bot
sydevs-bot enabled auto-merge October 27, 2026 01:13
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 27, 2026
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Oct 27, 2026
Merged via the queue into main with commit f9ed7d3 Oct 27, 2026
64 of 67 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-331-calendar-view-switch branch October 27, 2026 01:20
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(calendar): the view switch lights an option a phone cannot render

3 participants