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 = `