fix(journey): decide the phone's all-layers view inside the layers hook, follow the tests to the facet chip and the attach plus

This commit is contained in:
Maurice
2026-10-22 21:55:12 +02:00
parent 8e420cc1f1
commit 98f7549ac5
5 changed files with 11 additions and 11 deletions
@@ -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.
@@ -136,10 +136,10 @@ describe('MToursSelectionList', () => {
const other = { ...tour, place_id: 43, name: 'Other', max_hiking_difficulty: 4 }
render(<List planner={planner({ tours: [tour, other] })} shell={shell()} />)
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()
})
})
@@ -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.
@@ -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
@@ -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 () => {