From 3b286d04c3596114b0b5efc0d5418d82435eb5f4 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 8 Nov 2026 02:45:34 +0000 Subject: [PATCH] feat(mobile): the tour detail edits on an iPad and an unfolded Duo The phone's tour sheet reads the tour and plans it onto a day. In the wide and split size classes it now edits what the desktop's tour card edits, through the same useTourDetailActions: the name and the colour, a copy saved as a new tour, the recorded tracks, the packing list it points at and its files, for a member who may edit places. The phone is unchanged. --- .../screens/trip/sheets/MTripSheets.test.tsx | 36 +++++++++++++++++-- .../screens/trip/sheets/MTripSheets.tsx | 15 ++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx b/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx index b09f6725b..c47641b2e 100644 --- a/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx +++ b/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx @@ -1,11 +1,12 @@ import { fireEvent, render, screen } from '../../../../../tests/helpers/render' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { TourListItem } from '@trek/shared' import { buildPlace } from '../../../../../tests/helpers/factories' import { resetAllStores, seedStore } from '../../../../../tests/helpers/store' import { useSettingsStore } from '../../../../store/settingsStore' import type { TripPlanner } from '../MTripShell' import { MSelectedTourDetail } from './MTripSheets' +import { _pinSizeClass } from '../../../../hooks/sizeClass' const place = buildPlace({ id: 42, @@ -58,6 +59,10 @@ function planner(overrides: Partial = {}): TripPlanner { } as unknown as TripPlanner } +afterEach(() => { + _pinSizeClass(null) +}) + beforeEach(() => { resetAllStores() vi.clearAllMocks() @@ -108,4 +113,31 @@ describe('MSelectedTourDetail', () => { expect(screen.queryByRole('dialog')).not.toBeInTheDocument() expect(document.querySelector('#tour-elevation-42')).not.toBeInTheDocument() }) -}) \ No newline at end of file + + it('FE-MOB-TOURDETAIL-001: the phone reads the tour, with no way to rename it', () => { + render((() => true) })} />) + + expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument() + }) + + it('FE-MOB-TOURDETAIL-002: an iPad edits the tour as the desktop card does, through the shared actions', async () => { + _pinSizeClass('wide') + const p = planner({ can: vi.fn(() => true) }) + render() + + fireEvent.click(screen.getByRole('button', { name: 'Edit' })) + const field = screen.getByRole('textbox', { name: 'Name' }) + fireEvent.change(field, { target: { value: 'Ridge walk long' } }) + fireEvent.keyDown(field, { key: 'Enter' }) + + await vi.waitFor(() => expect(p.tripActions.updatePlace).toHaveBeenCalledWith(7, 42, { name: 'Ridge walk long' })) + await vi.waitFor(() => expect(p.reloadTourPlaceIds).toHaveBeenCalled()) + }) + + it('FE-MOB-TOURDETAIL-003: on an iPad a member who may not edit places still only reads', () => { + _pinSizeClass('split') + render() + + expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument() + }) +}) diff --git a/client/src/mobile/screens/trip/sheets/MTripSheets.tsx b/client/src/mobile/screens/trip/sheets/MTripSheets.tsx index cee5a923b..dfa9958bd 100644 --- a/client/src/mobile/screens/trip/sheets/MTripSheets.tsx +++ b/client/src/mobile/screens/trip/sheets/MTripSheets.tsx @@ -5,6 +5,8 @@ import TourDetailDialog from '../../../../components/Tours/TourDetailDialog' import { useBookingExpenseEditor } from '../../../../pages/tripPlanner/useBookingExpenseEditor' import { applyTripCoverUpdate } from '../../../../pages/tripPlanner/tripCover' import { latestReservation } from '../../../../pages/tripPlanner/transportEditorOpeners' +import { useTourDetailActions } from '../../../../pages/tripPlanner/useTourDetailActions' +import { useIsWide } from '../../../../hooks/sizeClass' import MConfirmSheet from '../../settings/MConfirmSheet' import MDayImpactList from '../../../components/MDayImpactList' import MDaySheet from './MDaySheet' @@ -41,11 +43,18 @@ import { useLastOpen } from '../../../../components/shared/usePresence' * The one global mobile tour-detail owner, independent of which surface * selected it. The tour shows in a sheet like every other detail * (MTourDetailShell); it keeps the tour it showed last while it slides away. + * + * On the phone it reads, and plans the tour onto a day. On an iPad or an + * unfolded Duo it edits what the desktop's tour card edits, through the same + * useTourDetailActions: the name and colour, a copy saved as a new tour, the + * recorded tracks, the packing list it points at and its files. */ export function MSelectedTourDetail({ planner }: Pick) { const open = !!(planner.selectedTour && planner.selectedPlace) const tour = useLastOpen(planner.selectedTour, open) const place = useLastOpen(planner.selectedPlace, open) + const actions = useTourDetailActions(planner) + const canEdit = useIsWide() && planner.can('place_edit', planner.trip) if (!tour || !place) return null return ( @@ -59,9 +68,11 @@ export function MSelectedTourDetail({ planner }: Pick planner.tripActions.addFile(planner.tripId, fd) : undefined} onClose={() => planner.setSelectedPlaceId(null)} onAssignToDay={planner.handleAssignToDay} onRemoveAssignment={planner.handleRemoveAssignment}