diff --git a/client/src/components/Collections/useLibraryCount.ts b/client/src/components/Collections/useLibraryCount.ts index 01cb09f05..042040d5b 100644 --- a/client/src/components/Collections/useLibraryCount.ts +++ b/client/src/components/Collections/useLibraryCount.ts @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'; import { placesLibraryRepo } from '../../repo/placesLibraryRepo'; /** How many places All places holds, and how many of them are saved in a list; each place once. */ -export interface LibraryCounts { +interface LibraryCounts { all: number; saved: number; } diff --git a/client/src/components/Planner/PlaceInspector.tsx b/client/src/components/Planner/PlaceInspector.tsx index 55f498a06..907fce2f7 100644 --- a/client/src/components/Planner/PlaceInspector.tsx +++ b/client/src/components/Planner/PlaceInspector.tsx @@ -36,7 +36,7 @@ import { TRANSPORT_TYPES, getPlaceBookings } from '../../utils/dayMerge' import { NavigationMenu } from '../shared/NavigationMenu' import { centredMapCard, type MapCardPlacement } from '../Map/centredMapCard' import { resolveOpenNow, resolvePlaceTimeZone, getWeekdayIndex, type OpeningPeriod } from './placeOpenState' -import { closedHoursLine, convertHoursLine } from './placeHoursFormat' +import { closedHoursLines, convertHoursLine } from './placeHoursFormat' import type { EndDayControlProps } from '../Roadtrip/EndDayControl' import VisitControls, { type RoadtripStayControl } from '../Roadtrip/VisitControls' import { DialogButton, DialogIconButton, DialogSection, DeleteButton, FooterSpacer, fs } from '../shared/DialogShell' @@ -331,8 +331,7 @@ export default function PlaceInspector({ // Hours the traveller typed in win over looked-up ones (#2472): they are what // somebody actually checked, and a place nobody listed has no other source. const ownHours = hoursLines(place.opening_hours, locale, t('places.hoursClosed'), t('places.hoursAllDay')) - // A provider's closed day (OSM writes 'off') in the reader's words, as the own hours say it. - const openingHours = ownHours ?? googleDetails?.opening_hours?.map(line => closedHoursLine(line, t('places.hoursClosed'))) ?? null + const openingHours = ownHours ?? closedHoursLines(googleDetails?.opening_hours, t('places.hoursClosed')) const detailLat = place.lat ?? googleDetails?.lat const detailLng = place.lng ?? googleDetails?.lng const placeTimeZone = resolvePlaceTimeZone(detailLat, detailLng) diff --git a/client/src/components/Planner/placeHoursFormat.test.ts b/client/src/components/Planner/placeHoursFormat.test.ts index e286a6fd7..469bdc7e3 100644 --- a/client/src/components/Planner/placeHoursFormat.test.ts +++ b/client/src/components/Planner/placeHoursFormat.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest' -import { closedHoursLine, convertHoursLine, isUnknownHoursLine, splitHoursLine } from './placeHoursFormat' +import { closedHoursLine, closedHoursLines, convertHoursLine, isUnknownHoursLine, splitHoursLine } from './placeHoursFormat' describe('convertHoursLine', () => { it('FE-PLANNER-HOURS-001: a range that stays in one half of the day carries the meridiem back to its opener', () => { @@ -56,7 +56,7 @@ describe('isUnknownHoursLine', () => { }) describe('closedHoursLine', () => { - it('FE-PLANNER-HOURS-010: a day OSM tags off or closed reads as closed in the reader's words', () => { + it('FE-PLANNER-HOURS-010: a day OSM tags off or closed reads as closed in the words of the reader', () => { expect(closedHoursLine('Monday: off', 'Geschlossen')).toBe('Monday: Geschlossen') expect(closedHoursLine('Sunday: Closed', 'Fermé')).toBe('Sunday: Fermé') expect(closedHoursLine('off', 'Closed')).toBe('Closed') @@ -67,4 +67,9 @@ describe('closedHoursLine', () => { expect(closedHoursLine('Friday: 09:00-12:00 off', 'Closed')).toBe('Friday: 09:00-12:00 off') expect(closedHoursLine('', 'Closed')).toBe('') }) + + it('FE-PLANNER-HOURS-012: a whole week reads its closed days the same way, and no week stays none', () => { + expect(closedHoursLines(['Monday: off', 'Tuesday: 09:00-17:00'], 'Closed')).toEqual(['Monday: Closed', 'Tuesday: 09:00-17:00']) + expect(closedHoursLines(undefined, 'Closed')).toBeNull() + }) }) diff --git a/client/src/components/Planner/placeHoursFormat.ts b/client/src/components/Planner/placeHoursFormat.ts index 2a23656fd..f89e7f392 100644 --- a/client/src/components/Planner/placeHoursFormat.ts +++ b/client/src/components/Planner/placeHoursFormat.ts @@ -89,3 +89,8 @@ export function closedHoursLine(line: string, closedLabel: string): string { if (!/^(off|closed)$/i.test(times)) return line return day ? `${day}: ${closedLabel}` : closedLabel } + +/** A provider's whole week with its closed days in the reader's words; null without one. */ +export function closedHoursLines(lines: string[] | null | undefined, closedLabel: string): string[] | null { + return lines?.map(line => closedHoursLine(line, closedLabel)) ?? null +}