Make the Today link context-sensitive to time of day
Deploy / deploy (push) Successful in 1m26s

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CbHcmjnqQPJZ1i2yoebmp5
This commit is contained in:
2026-08-28 16:52:09 -04:00
parent 03d164f174
commit 17112c06a8
3 changed files with 88 additions and 5 deletions
+18 -1
View File
@@ -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 {
+2 -2
View File
@@ -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 = `
<nav class="day-nav" aria-label="Day navigation">
<a href="${prevUrl}" class="day-nav-btn" data-action="prev" aria-label="Previous day">&larr;</a>