Repository navigation
refactor(sidebar): move the sidebar's time rules into shared pure reducers - #29943
Conversation
…ntion into shared pure reducers
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
ELI5
The sidebar has a few rules that depend on time: wait three seconds before re-sorting after activity, keep Smart sort on the saved order until the first live signal, and keep a just-slept workspace visible briefly. Today those rules are tangled up with the window's timers and React code. This PR pulls the rules out into small plain functions that take the current time as an input. The window still runs them exactly as before, so nothing looks different.
What Changed
Before and after for the user: no change.
Mechanism:
src/shared/sidebar-list/sort-settle.ts(new):reduceSortSettle(state, event, now)returns the next state, including the settle deadline, and whether to settle now. Events are a store write or the deadline firing. The rules are the same as before: a bump restarts the three-second window, adds and removes settle at once (compared against the row count at the last bump), Manual and a mode switch settle at once, and a write that lands settled clears the deadline.src/renderer/src/store/settled-sort-epoch.ts: now a thin driver. It turns each store write into an event, holds the one timer that follows the reducer's deadline, and writessettledSortEpoch.src/shared/sidebar-list/smart-sort-phase.ts(new): names Smart's cold and live phases, and when ranks follow the saved order.use-sort-order.tsuses these instead of inline checks. The latch is still a ref in the hook, so it still resets when the list unmounts.sleeping-sweep-retention.tsmoved unchanged from the renderer tosrc/shared/sidebar-list/. Its hook already drove it with a timer.now, so it stays where it is.Why
A later PR will run these decisions once in the background process and publish the results, so a phone and the desktop show the same order. That needs the rules to be pure functions with no clock, timers or React inside. Moving them now, while the window still drives them, keeps that later PR small and makes this one easy to check: same rules, new home.
The Smart comparator and its attention scoring stay in the renderer for now. Moving them pulls in five renderer modules and about a hundred import sites, and it would collide with the parallel text-order change to the same comparator. They can move in the PR that first runs them in the background process.
Linked Issue
N/A, part of the sidebar list refactor that started with #29906.
Visual Proof
N/A. This is a refactor with no visible or interaction change.
Testing
New tests with an explicit clock: a settle burst restarting its window, adds and removes settling at once, Manual and mode switch, a settled write clearing the deadline, the Smart phases, the latch holding after its signal ends and resetting on unmount, and the exact create-grace boundary. I checked that the latch test fails when the latch is broken. The existing sidebar tests, the golden list fixtures and the store settle tests pass unchanged (804 test files under
src/shared/sidebar-list,src/shared/workspace-view,src/renderer/src/store,src/renderer/src/components/sidebar).pnpm tcand the changed-code quality gate pass.Review
A separate review found no behaviour change. Applied from it: the reducer now owns the Manual and mode-switch rule instead of getting a ready-made flag, and the write event type no longer allows a bump without a row count.
Agent skill upstream boundary
Notes
Renderer only, with pure shared code. No wire, SSH, mobile or platform impact.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)