From 27b69d9797e7728c36276d1377e5a5710281074d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 15 Oct 2026 10:20:26 +0000 Subject: [PATCH] refactor(web): share the now-cue pulse subscription and flatten go-to-today Four components each subscribed to the now-cue store twice and rebuilt the same remount key by hand, so the trick that makes a CSS animation replay was re-explained at every call site. Fold both subscriptions into useNowCuePulse and let it mint the key. Also flatten scrollToNowOrPulse's nested already-at-now branch into two reads and two statements, drop the dead motion-reduce:transition-none that rode along with animation-only classes (the pulse utilities already carry motion-reduce:animate-none, and none of these elements transition), and unexport the two grid helpers that only grid.util uses. No behavior change. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01WpxnkYFrv7Y6BGCCQL55vM --- .../src/common/utils/grid/grid.util.ts | 4 +-- .../src/components/SelectView/SelectView.tsx | 17 ++++--------- .../src/grid/components/TimedGrid.tsx | 13 +++------- .../grid/now-cue/scroll-to-now-or-pulse.ts | 23 +++++++---------- .../src/grid/now-cue/useNowCuePulse.ts | 25 +++++++++++++++++++ .../Week/components/Header/DayLabels.tsx | 19 +++++--------- 6 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 apps/calendar-web/src/grid/now-cue/useNowCuePulse.ts diff --git a/apps/calendar-web/src/common/utils/grid/grid.util.ts b/apps/calendar-web/src/common/utils/grid/grid.util.ts index 98174f979..9993515c1 100644 --- a/apps/calendar-web/src/common/utils/grid/grid.util.ts +++ b/apps/calendar-web/src/common/utils/grid/grid.util.ts @@ -67,7 +67,7 @@ export const SCROLL_TO_NOW_BUFFER_PX = 150; const SCROLL_TO_NOW_TOLERANCE_PX = 2; /** When the now line is visible and scroll is within this window, "t" pulses. */ -export const SCROLL_TO_NOW_PULSE_NEAR_MINUTES = 5; +const SCROLL_TO_NOW_PULSE_NEAR_MINUTES = 5; export const getScrollToNowTop = (clientHeight: number) => Math.max( @@ -76,7 +76,7 @@ export const getScrollToNowTop = (clientHeight: number) => SCROLL_TO_NOW_BUFFER_PX, ); -export const getScrollToNowDelta = (timedGrid: HTMLElement) => { +const getScrollToNowDelta = (timedGrid: HTMLElement) => { const targetTop = getScrollToNowTop(timedGrid.clientHeight); return Math.abs(timedGrid.scrollTop - targetTop); }; diff --git a/apps/calendar-web/src/components/SelectView/SelectView.tsx b/apps/calendar-web/src/components/SelectView/SelectView.tsx index 47de58fef..06038ded7 100644 --- a/apps/calendar-web/src/components/SelectView/SelectView.tsx +++ b/apps/calendar-web/src/components/SelectView/SelectView.tsx @@ -18,11 +18,7 @@ import { import { ROOT_ROUTES } from "@web/common/constants/routes"; import { Z_INDEX_FLOATING_MENU } from "@web/common/constants/web.constants"; import { ShortcutKeys } from "@web/components/Shortcuts/ShortcutKeys"; -import { - selectNowCueActive, - selectNowCuePulseGeneration, - useNowCueStore, -} from "@web/grid/now-cue/now-cue.store"; +import { useNowCuePulse } from "@web/grid/now-cue/useNowCuePulse"; import { useFloatingLayer } from "@web/shortcuts/floating-layer"; import { pageJumpAttrs } from "@web/shortcuts/page-jump/page-jump.targets"; import { pulseClickTaughtShortcut } from "@web/shortcuts/pointer-intent/pulseClickTaughtShortcut"; @@ -52,8 +48,8 @@ export const SelectView = ({ const navigate = useNavigate(); const listRef = useRef>([]); useFloatingLayer("viewSelect", isOpen); - const pulseDayLabel = useNowCueStore(selectNowCueActive) && emphasizeDayLabel; - const pulseGeneration = useNowCueStore(selectNowCuePulseGeneration); + const { pulsing, pulseKey } = useNowCuePulse(); + const pulseDayLabel = pulsing && emphasizeDayLabel; const getCurrentView = (): "Day" | "Week" | "Life" => { const pathname = location.pathname; @@ -188,11 +184,8 @@ export const SelectView = ({ aria-controls={isOpen ? dropdownId : undefined} > {label} diff --git a/apps/calendar-web/src/grid/components/TimedGrid.tsx b/apps/calendar-web/src/grid/components/TimedGrid.tsx index 9a8abfdb2..5892f7f82 100644 --- a/apps/calendar-web/src/grid/components/TimedGrid.tsx +++ b/apps/calendar-web/src/grid/components/TimedGrid.tsx @@ -23,11 +23,7 @@ import { TIMED_VISIBLE_HOURS, } from "@web/grid/grid.constants"; import { useGridMarginLeft } from "@web/grid/grid-margin"; -import { - selectNowCueActive, - selectNowCuePulseGeneration, - useNowCueStore, -} from "@web/grid/now-cue/now-cue.store"; +import { useNowCuePulse } from "@web/grid/now-cue/useNowCuePulse"; import { type GridVisibleDate } from "@web/grid/types/grid.types"; import { allDayColumnTintStyle } from "@web/grid/utils/allDayColumnTint.util"; import { @@ -164,17 +160,16 @@ const CalendarNowLine = ({ }) => { useMinuteTick(); const percentOfDay = getCurrentPercentOfDay(effectiveTimeZone); - const pulseNowLine = useNowCueStore(selectNowCueActive); - const pulseGeneration = useNowCueStore(selectNowCuePulseGeneration); + const { pulsing: pulseNowLine, pulseKey } = useNowCuePulse(); return (