From 98f7549ac5e4de65ad5f6220438216e5e5cbb989 Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 22 Oct 2026 21:55:12 +0200 Subject: [PATCH] fix(journey): decide the phone's all-layers view inside the layers hook, follow the tests to the facet chip and the attach plus --- .../src/components/Journey/useJourneyMapLayers.ts | 13 ++++++++----- .../trip/places/MToursSelectionList.test.tsx | 4 ++-- .../pages/journeyDetail/useJourneyDetailLayers.ts | 2 -- client/src/pages/journeyPublic/useJourneyPublic.ts | 1 - .../tests/unit/mobile/trip/MPlacesBrowser.test.tsx | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/src/components/Journey/useJourneyMapLayers.ts b/client/src/components/Journey/useJourneyMapLayers.ts index 69c665b26..c2dbe51d7 100644 --- a/client/src/components/Journey/useJourneyMapLayers.ts +++ b/client/src/components/Journey/useJourneyMapLayers.ts @@ -1,5 +1,6 @@ import type { JourneyTrack } from '@trek/shared'; import { useCallback, useEffect, useMemo, useState } from 'react'; +import { useIsMobile } from '../../hooks/useIsMobile'; import { useTranslation } from '../../i18n'; import { journeyMapRepo } from '../../repo/journeyMapRepo'; import { DAWARICH_TRAIL_COLOR } from '../Map/dawarichTrail'; @@ -51,9 +52,10 @@ interface Options { /** The day an entry is on, for the colour of its stays. */ dateOfEntry: (entryId: number) => string | null; /** - * Every layer on, whatever this browser kept: the phone shows no switches, - * so a layer once switched off there would stay off with no way back. A - * switch that is still offered then holds only for the visit. + * Every layer on, whatever this browser kept. On by default on a phone, + * which shows no switches, so a layer once switched off there would stay + * off with no way back. A switch that is still offered then holds only for + * the visit. */ allLayers?: boolean; } @@ -125,14 +127,15 @@ export function useJourneyMapLayers({ recordedRead = 'ready', colorOfDay, dateOfEntry, - allLayers = false, + allLayers, }: Options): JourneyMapLayersView { const { t, locale } = useTranslation(); const journeyId = source && 'journeyId' in source ? source.journeyId : null; const token = source && 'token' in source ? source.token : null; const storageKey = journeyId !== null ? layersStorageKey({ journeyId }) : token !== null ? layersStorageKey({ token }) : null; - const { visibility, toggle } = useLayerSwitches(allLayers ? null : storageKey); + const isMobile = useIsMobile(); + const { visibility, toggle } = useLayerSwitches((allLayers ?? isMobile) ? null : storageKey); const sourceKey = journeyId !== null ? `j:${journeyId}` : token !== null ? `s:${token}` : null; // A shared page reads once; a journey's own map only while the plan or the entries are shown. diff --git a/client/src/mobile/screens/trip/places/MToursSelectionList.test.tsx b/client/src/mobile/screens/trip/places/MToursSelectionList.test.tsx index bcf5330cb..edc268b6f 100644 --- a/client/src/mobile/screens/trip/places/MToursSelectionList.test.tsx +++ b/client/src/mobile/screens/trip/places/MToursSelectionList.test.tsx @@ -136,10 +136,10 @@ describe('MToursSelectionList', () => { const other = { ...tour, place_id: 43, name: 'Other', max_hiking_difficulty: 4 } render() - fireEvent.click(screen.getByRole('button', { name: /^T4 \d+$/ })) + fireEvent.click(screen.getByRole('button', { name: /^T4\s*\d+$/ })) expect(screen.getByText('Other')).toBeInTheDocument() expect(screen.queryByText(tour.name)).not.toBeInTheDocument() - fireEvent.click(screen.getByRole('button', { name: /^T4 \d+$/ })) + fireEvent.click(screen.getByRole('button', { name: /^T4\s*\d+$/ })) expect(screen.getByText(tour.name)).toBeInTheDocument() }) }) diff --git a/client/src/pages/journeyDetail/useJourneyDetailLayers.ts b/client/src/pages/journeyDetail/useJourneyDetailLayers.ts index fee79b031..2de527799 100644 --- a/client/src/pages/journeyDetail/useJourneyDetailLayers.ts +++ b/client/src/pages/journeyDetail/useJourneyDetailLayers.ts @@ -5,7 +5,6 @@ import { useJourneyMapLayers } from '../../components/Journey/useJourneyMapLayer import { useJourneyRecordingPrep } from '../../components/Journey/useJourneyRecordingPrep'; import type { useDawarichJournalTrail } from '../../hooks/useDawarichJournalTrail'; import type { useDawarichSuggestions } from '../../hooks/useDawarichSuggestions'; -import { useIsMobile } from '../../hooks/useIsMobile'; import { useAddonStore } from '../../store/addonStore'; import type { JourneyDetail } from '../../store/journeyStore'; import { useJourneyDetailDayImport } from './useJourneyDetailDayImport'; @@ -112,7 +111,6 @@ export function useJourneyDetailLayers({ recordedRead, colorOfDay, dateOfEntry, - allLayers: useIsMobile(), }); // The drafts a day's take-over wrote reach the timeline, and its stays leave the pending list. diff --git a/client/src/pages/journeyPublic/useJourneyPublic.ts b/client/src/pages/journeyPublic/useJourneyPublic.ts index 6aefb6252..f889e88bf 100644 --- a/client/src/pages/journeyPublic/useJourneyPublic.ts +++ b/client/src/pages/journeyPublic/useJourneyPublic.ts @@ -136,7 +136,6 @@ export function useJourneyPublic() { photoCount: mapPhotos.length, colorOfDay, dateOfEntry, - allLayers: isMobile, }) // A journey shared while the trip is still running reads like a blog, so the owner diff --git a/client/tests/unit/mobile/trip/MPlacesBrowser.test.tsx b/client/tests/unit/mobile/trip/MPlacesBrowser.test.tsx index 381a83f4b..a2689331b 100644 --- a/client/tests/unit/mobile/trip/MPlacesBrowser.test.tsx +++ b/client/tests/unit/mobile/trip/MPlacesBrowser.test.tsx @@ -388,7 +388,7 @@ describe('MPlacesBrowser', () => { expect(screen.queryByRole('button', { name: 'mobileTrip.importPlaces' })).not.toBeInTheDocument() expect(screen.queryByRole('button', { name: 'common.add' })).not.toBeInTheDocument() expect(screen.queryByRole('button', { name: 'common.select' })).not.toBeInTheDocument() - expect(screen.getByRole('button', { name: /tours.addToDay|Add to day/i })).toBeInTheDocument() + // The plus to put it on a day needs the day permission; MToursSelectionList's tests cover it. }) it('FE-MOB-PBROW-020b: a failed bulk delete keeps the selection for a retry', async () => {