From 17112c06a841a666fe6aa991df77b78d7d171af0 Mon Sep 17 00:00:00 2001 From: Will Estes Date: Fri, 28 Aug 2026 16:52:09 -0400 Subject: [PATCH] Make the Today link context-sensitive to time of day When already viewing today, clicking Today now snaps the selected hour to whatever hour would be default for the current wall-clock time (same as a fresh visit to /vu); when viewing another date it still just jumps to today while preserving the current hour, as before. The link's href is built from the same todayTargetHour() decision as the click handler, so right-click -> open in new tab lands on the same target instead of following a stale href. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01CbHcmjnqQPJZ1i2yoebmp5 --- src/app-state.ts | 19 ++++++++++- src/ui/day-nav.ts | 4 +-- tests/app-state.test.ts | 70 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/src/app-state.ts b/src/app-state.ts index d3de814..80cea26 100644 --- a/src/app-state.ts +++ b/src/app-state.ts @@ -56,8 +56,25 @@ export function setDate(date: string): void { notify(); } +/** + * Which hour the "Today" link should point to: if we're already viewing + * today, the current time-of-day default (as if freshly visiting `/vu` + * right now); otherwise the hour currently selected, unchanged. Shared by + * `goToToday()` and the link's `href` (`day-nav.ts`) so a plain click and + * a right-click-open-in-new-tab land on the same target. + */ +export function todayTargetHour(): HourId { + return state.date === todayIso() ? defaultHourForTime(new Date()) : state.selectedHour; +} + export function goToToday(): void { - setDate(todayIso()); + const today = todayIso(); + const hour = todayTargetHour(); + if (state.date === today) { + setSelectedHour(hour); + } else { + setDate(today); + } } export function addDays(date: string, days: number): string { diff --git a/src/ui/day-nav.ts b/src/ui/day-nav.ts index cdfb8be..9c90545 100644 --- a/src/ui/day-nav.ts +++ b/src/ui/day-nav.ts @@ -1,4 +1,4 @@ -import { getState, shiftDate, goToToday, addDays, todayIso } from '../app-state'; +import { getState, shiftDate, goToToday, addDays, todayIso, todayTargetHour } from '../app-state'; import { resolveDay } from '../calendar'; import { resolveEveningDay } from '../calendar/vespers'; import { getDayLabel, getVespersStatusLabel } from '../calendar/day-label'; @@ -26,7 +26,7 @@ export function renderDayNav(container: HTMLElement): void { const vespersStatus = selectedHour === 'vespers' ? getVespersStatusLabel(day) : undefined; const prevUrl = urlFor(addDays(date, -1), selectedHour, languages); const nextUrl = urlFor(addDays(date, 1), selectedHour, languages); - const todayUrl = urlFor(todayIso(), selectedHour, languages); + const todayUrl = urlFor(todayIso(), todayTargetHour(), languages); container.innerHTML = `