mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
feat(trip-settings): edit the trip inside its settings, in one look across the areas and the trip form
Edit trip is an area of the settings dialog, beside People, Sharing and Journal, instead of a second dialog. The side column names the areas only, the dialog keeps one height, and every area uses the same cards, fields and buttons; the trip form on its own takes the same head, cards and buttons. A trip that loads quickly opens without the splash on the desktop too.
This commit is contained in:
@@ -92,7 +92,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
|
||||
highlightedAlternative, setHighlightedAlternative,
|
||||
moveRoadtripStopToDay,
|
||||
dropPoiOnRoute,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal, editTripFromSettings,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal,
|
||||
showReservationModal, setShowReservationModal, editingReservation, setEditingReservation,
|
||||
showBookingImport, setShowBookingImport, bookingImportKind, setBookingImportKind, bookingImportAvailable,
|
||||
airTrailAvailable, showAirTrailImport, setShowAirTrailImport,
|
||||
@@ -123,7 +123,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
|
||||
selectedPlace, dayOrderMap, dayPlaces,
|
||||
toursEnabled, toursMode, setToursMode, tours, toursLoading, tourDataReady, tourPlaceIds,
|
||||
invalidateTourPlaceIds, selectedTour,
|
||||
mapTileUrl, fontStyle, splashDone, assistantMap,
|
||||
mapTileUrl, fontStyle, slowOpen, saveTrip, assistantMap,
|
||||
} = pageState.planner
|
||||
const {
|
||||
poi,
|
||||
@@ -183,13 +183,13 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
|
||||
// the day-header tram button and the modal's mode switch — is off without one.
|
||||
const tripHasDates = Boolean(trip?.start_date && trip?.end_date)
|
||||
|
||||
if (isLoading || !splashDone) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="bg-surface" style={{
|
||||
<div className="bg-surface" aria-busy="true" style={{
|
||||
minHeight: '100vh', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
|
||||
...fontStyle,
|
||||
}}>
|
||||
<TripLoadingSplash title={trip?.title} />
|
||||
{slowOpen && <TripLoadingSplash title={trip?.title} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -826,11 +826,11 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
|
||||
<TripFormModal
|
||||
isOpen={showTripForm}
|
||||
onClose={() => setShowTripForm(false)}
|
||||
onSave={async (data) => { await tripActions.updateTrip(tripId, data); loadAccommodations(); toast.success(t('trip.toast.tripUpdated')) }}
|
||||
onSave={saveTrip}
|
||||
trip={trip}
|
||||
onCoverUpdate={applyTripCoverUpdate}
|
||||
/>
|
||||
<TripMembersModal isOpen={showMembersModal} onClose={() => setShowMembersModal(false)} tripId={tripId} tripTitle={trip?.title} onMembersChanged={refreshMembers} onEditTrip={can('trip_edit', trip) ? editTripFromSettings : undefined} />
|
||||
<TripMembersModal isOpen={showMembersModal} onClose={() => setShowMembersModal(false)} tripId={tripId} tripTitle={trip?.title} onMembersChanged={refreshMembers} editTrip={trip && can('trip_edit', trip) ? { trip, onSave: saveTrip, onCoverUpdate: applyTripCoverUpdate } : undefined} />
|
||||
<ReservationModal isOpen={showReservationModal} onClose={() => { if (importReviewActive) { advanceImportReview() } else { setShowReservationModal(false); setEditingReservation(null); setBookingForAssignmentId(null) } }} onSave={async (data, steps) => { const r = await handleSaveReservation(data, steps); if (importReviewActive && r) advanceImportReview(); return r }} reservation={editingReservation} prefill={reservationPrefill} days={days} places={places} assignments={assignments} selectedDayId={selectedDayId} files={files} onFileUpload={canUploadFiles ? (fd) => tripActions.addFile(tripId, fd) : undefined} onFileDelete={(id) => tripActions.deleteFile(tripId, id)} accommodations={tripAccommodations} defaultAssignmentId={bookingForAssignmentId} onOpenExpense={openBookingExpense} tripMembers={tripMembers} />
|
||||
{showTransportModal && (
|
||||
<ErrorBoundary boundaryId="planner-panel:transport" fallback={null}>
|
||||
|
||||
@@ -328,6 +328,7 @@ function mapState(): HookState {
|
||||
selectedTour: null,
|
||||
mapTileUrl: 'https://tiles/{z}/{x}/{y}.png',
|
||||
fontStyle: { fontFamily: 'var(--font-system)' },
|
||||
splashDone: true,
|
||||
slowOpen: false,
|
||||
saveTrip: vi.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -638,21 +638,25 @@ describe('TripPlannerPage — shell', () => {
|
||||
expect(plannerActions.viewGpxTour).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-002: the splash holds the page until the trip finished loading', () => {
|
||||
renderPage({ isLoading: true, splashDone: false })
|
||||
it('FE-PAGE-TPW-002: a slow open shows the splash until the trip finished loading', () => {
|
||||
renderPage({ isLoading: true, slowOpen: true })
|
||||
|
||||
expect(screen.getByRole('status')).toHaveTextContent('Kyoto')
|
||||
expect(screen.queryByTestId('map-view')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-003: the splash also covers the gap between load and splashDone', () => {
|
||||
renderPage({ isLoading: false, splashDone: false })
|
||||
it('FE-PAGE-TPW-003: a quick open shows no splash, only the empty page while it loads, and the trip at once', () => {
|
||||
const view = renderPage({ isLoading: true, slowOpen: false })
|
||||
expect(screen.queryByTestId('splash')).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('map-view')).not.toBeInTheDocument()
|
||||
view.unmount()
|
||||
|
||||
expect(screen.getByTestId('splash')).toBeInTheDocument()
|
||||
renderPage({ isLoading: false, slowOpen: false })
|
||||
expect(screen.queryByTestId('splash')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-004: a trip that never arrived renders nothing at all', () => {
|
||||
const { container } = renderPage({ trip: null, isLoading: false, splashDone: true })
|
||||
const { container } = renderPage({ trip: null, isLoading: false, slowOpen: false })
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
@@ -1518,13 +1522,10 @@ describe('TripPlannerPage — modals', () => {
|
||||
expect((props('placeForm').dayAssignments as unknown as unknown[]).length).toBe(1)
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-047: saving the trip form reloads the accommodations and confirms', async () => {
|
||||
it('FE-PAGE-TPW-047: the trip form saves through the hook, the same save the trip settings use', () => {
|
||||
renderPage()
|
||||
|
||||
await act(async () => { await props('tripForm').onSave({ title: 'Kyoto 2' }) })
|
||||
const tripActions = hookState.tripActions as Record<string, ReturnType<typeof vi.fn>>
|
||||
expect(tripActions.updateTrip).toHaveBeenCalledWith(42, { title: 'Kyoto 2' })
|
||||
expect(hookState.loadAccommodations).toHaveBeenCalled()
|
||||
expect(props('tripForm').onSave).toBe(hookState.saveTrip)
|
||||
|
||||
act(() => { props('tripForm').onClose() })
|
||||
expect(hookState.setShowTripForm).toHaveBeenCalledWith(false)
|
||||
@@ -1552,12 +1553,12 @@ describe('TripPlannerPage — modals', () => {
|
||||
expect(hookState.setShowMembersModal).toHaveBeenCalledWith(false)
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-075: the members modal leads to the trip form only for someone who may edit the trip (#2811)', () => {
|
||||
it('FE-PAGE-TPW-075: the trip settings hold the trip form only for someone who may edit the trip (#2811)', () => {
|
||||
renderPage()
|
||||
expect(props('membersModal').onEditTrip).toBe(hookState.editTripFromSettings)
|
||||
expect(props('membersModal').editTrip).toBeTruthy()
|
||||
|
||||
renderPage({ can: vi.fn((action: string) => action !== 'trip_edit') })
|
||||
expect(props('membersModal').onEditTrip).toBeUndefined()
|
||||
expect(props('membersModal').editTrip).toBeUndefined()
|
||||
})
|
||||
|
||||
it('FE-PAGE-TPW-050: closing the booking modal outside a review resets the editor', async () => {
|
||||
|
||||
@@ -248,14 +248,4 @@ describe('usePlannerDialogs', () => {
|
||||
act(() => { result.current.changeTransitRoute(buildReservation({ id: 15, type: 'transit' })) })
|
||||
expect(result.current.transitPrefill).toEqual({ from: null, to: null })
|
||||
})
|
||||
|
||||
it('FE-TP-DIALOGS-013: editing the trip from its settings swaps the settings for the trip form (#2811)', () => {
|
||||
const { result } = renderDialogs()
|
||||
act(() => { result.current.setShowMembersModal(true) })
|
||||
|
||||
act(() => { result.current.editTripFromSettings() })
|
||||
|
||||
expect(result.current.showMembersModal).toBe(false)
|
||||
expect(result.current.showTripForm).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -104,12 +104,6 @@ export function usePlannerDialogs(options: PlannerDialogsOptions) {
|
||||
}, [searchParams])
|
||||
const [showTripForm, setShowTripForm] = useState<boolean>(false)
|
||||
const [showMembersModal, setShowMembersModal] = useState<boolean>(false)
|
||||
// The trip settings hand over to the trip's form rather than stack a second dialog
|
||||
// on their own: the planner's way to the title, dates, cover and currency (#2811).
|
||||
const editTripFromSettings = useCallback(() => {
|
||||
setShowMembersModal(false)
|
||||
setShowTripForm(true)
|
||||
}, [])
|
||||
const [showReservationModal, setShowReservationModal] = useState<boolean>(false)
|
||||
const [editingReservation, setEditingReservation] = useState<Reservation | null>(null)
|
||||
const [showBookingImport, setShowBookingImport] = useState<boolean>(false)
|
||||
@@ -173,7 +167,7 @@ export function usePlannerDialogs(options: PlannerDialogsOptions) {
|
||||
editingAssignmentId, setEditingAssignmentId, placeFormDayId, setPlaceFormDayId,
|
||||
placeFormPosition, setPlaceFormPosition, serviceStopForm, setServiceStopForm, serviceStopKind, setServiceStopKind,
|
||||
stopDraft, setStopDraft, stayRelease, setStayRelease, reservationModalDayId, setReservationModalDayId,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal, editTripFromSettings,
|
||||
showTripForm, setShowTripForm, showMembersModal, setShowMembersModal,
|
||||
showReservationModal, setShowReservationModal, editingReservation, setEditingReservation,
|
||||
showBookingImport, setShowBookingImport, bookingImportKind, setBookingImportKind,
|
||||
bookingImportAvailable, setBookingImportAvailable, airTrailAvailable, showAirTrailImport, setShowAirTrailImport,
|
||||
|
||||
@@ -296,15 +296,14 @@ describe('useTripPlanner — bootstrap', () => {
|
||||
expect(accommodationRepo.list).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('FE-TP-HOOK-012: the splash gate opens once the trip finished loading', async () => {
|
||||
it('FE-TP-HOOK-012: a trip that opens at once never asks for the splash, and holds no minimum', async () => {
|
||||
vi.useFakeTimers()
|
||||
seedTrip()
|
||||
|
||||
const { result } = await renderPlanner()
|
||||
expect(result.current.splashDone).toBe(false)
|
||||
|
||||
await act(async () => { vi.advanceTimersByTime(1600) })
|
||||
expect(result.current.splashDone).toBe(true)
|
||||
expect(result.current.slowOpen).toBe(false)
|
||||
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
@@ -68,6 +68,7 @@ import { usePlannerTripView } from './usePlannerTripView'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
import { useIsWide } from '../../hooks/sizeClass'
|
||||
import { useRoadtripVias } from '../../components/Roadtrip/useRoadtripVias'
|
||||
import { TRIP_SPLASH_AFTER_MS } from '../../components/shared/useTripSplashBeats'
|
||||
|
||||
/**
|
||||
* The trip's roster from the server: the owner and the members. Null offline
|
||||
@@ -698,14 +699,22 @@ export function useTripPlanner() {
|
||||
|
||||
const fontStyle = { fontFamily: "var(--font-system)" }
|
||||
|
||||
// Splash screen — show for initial load + a brief moment for photos to start loading
|
||||
const [splashDone, setSplashDone] = useState(false)
|
||||
// The trip's form saves alike from its own dialog and from the trip settings (#2811).
|
||||
const saveTrip = useCallback(async (data: Parameters<typeof tripActions.updateTrip>[1]) => {
|
||||
await tripActions.updateTrip(tripId, data)
|
||||
loadAccommodations()
|
||||
toast.success(t('trip.toast.tripUpdated'))
|
||||
}, [tripActions, tripId, loadAccommodations, toast, t])
|
||||
|
||||
// The splash only for a slow open, as on the phone (MTripOpening): a trip that
|
||||
// loads within TRIP_SPLASH_AFTER_MS opens straight away, with no splash and no
|
||||
// minimum on screen.
|
||||
const [slowOpen, setSlowOpen] = useState(false)
|
||||
useEffect(() => {
|
||||
if (!isLoading && trip) {
|
||||
const timer = setTimeout(() => setSplashDone(true), 1500)
|
||||
return () => clearTimeout(timer)
|
||||
}
|
||||
}, [isLoading, trip])
|
||||
if (!isLoading) return
|
||||
const timer = setTimeout(() => setSlowOpen(true), TRIP_SPLASH_AFTER_MS)
|
||||
return () => clearTimeout(timer)
|
||||
}, [isLoading])
|
||||
|
||||
return {
|
||||
tripId, navigate, toast, t, language, locale, settings, placesPhotosEnabled,
|
||||
@@ -779,7 +788,7 @@ export function useTripPlanner() {
|
||||
...dayClear,
|
||||
handleSaveReservation, handleSaveTransport, handleDeleteReservation,
|
||||
selectedPlace, dayOrderMap, dayPlaces,
|
||||
mapTileUrl, fontStyle, splashDone,
|
||||
mapTileUrl, fontStyle, slowOpen, saveTrip,
|
||||
// The assistant on the map, handed to MapViewAuto whole by both shells.
|
||||
assistantMap,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user