mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
feat(roadtrip): show the place photo on the stop sheet and the stop dialog (#2629)
On the road a stop's picture is often what decides whether it is worth the detour. The phone's stop sheet shows the place's picture full width under its name and the desktop stop dialog shows it in place of the kind tile; both open the place's photos on tap. The picture is the place's own image, else the provider photo for its Google or OSM id through the shared photo cache.
This commit is contained in:
@@ -8,8 +8,10 @@ import type { CorridorPoi } from './useCorridorPois'
|
||||
|
||||
// The dialog carries the charging panel, which reads the open availability data for a
|
||||
// station that is not on the trip yet. Both of its collaborators are stubbed: the trip
|
||||
// is whichever one is open, and the data comes off the network.
|
||||
vi.mock('../../store/tripStore', () => ({ useTripStore: (select: (s: { trip: { id: number } }) => unknown) => select({ trip: { id: 1 } }) }))
|
||||
// is whichever one is open, and the data comes off the network. The trip's places are
|
||||
// what a stop being edited shows its picture from (#2629).
|
||||
const tripState = vi.hoisted(() => ({ trip: { id: 1 }, places: [] as Array<Record<string, unknown>> }))
|
||||
vi.mock('../../store/tripStore', () => ({ useTripStore: (select: (s: typeof tripState) => unknown) => select(tripState) }))
|
||||
vi.mock('../../repo/chargingRepo', () => ({ chargingRepo: { read: vi.fn(), readAt: vi.fn() } }))
|
||||
|
||||
const wrap = (ui: React.ReactElement) => render(<TranslationProvider>{ui}</TranslationProvider>)
|
||||
@@ -21,7 +23,10 @@ const charging = {
|
||||
tariffs: [], pricesUnavailable: false,
|
||||
}
|
||||
|
||||
beforeEach(() => { vi.clearAllMocks() })
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
tripState.places = []
|
||||
})
|
||||
|
||||
function poi(over: Partial<CorridorPoi> = {}): CorridorPoi {
|
||||
return {
|
||||
@@ -394,6 +399,22 @@ describe('editing a roadtrip stop', () => {
|
||||
expect(screen.getByRole('button', { name: 'Overnight' })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(screen.getByRole('textbox', { name: 'Check-in' })).toHaveValue('15:45')
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-STOPPOPUP-035: a stop on the trip shows its picture in place of the tile, and it opens the photos (#2629)', () => {
|
||||
tripState.places = [{ id: 7, name: 'Aral Autohof', lat: 53.1, lng: 10.2, image_url: '/uploads/places/aral.jpg' }]
|
||||
wrap(<RoadtripStopPopup draft={draft({ editing: { placeId: 7, stopType: 'fuel', dwellMinutes: 10 } })} {...noop} />)
|
||||
|
||||
const trigger = screen.getByRole('button', { name: 'Show photos' })
|
||||
expect(trigger.querySelector('img')).toHaveAttribute('src', '/uploads/places/aral.jpg')
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-STOPPOPUP-036: a hit from the search is no place yet and keeps the tile of its kind', () => {
|
||||
tripState.places = [{ id: 7, name: 'Aral Autohof', lat: 53.1, lng: 10.2, image_url: '/uploads/places/aral.jpg' }]
|
||||
const { container } = wrap(<RoadtripStopPopup draft={draft()} {...noop} />)
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Show photos' })).toBeNull()
|
||||
expect(container.ownerDocument.querySelector('img[src="/uploads/places/aral.jpg"]')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ import { PANEL, Segmented } from '../shared/dialogParts'
|
||||
import CustomTimePicker from '../shared/CustomTimePicker'
|
||||
import StayPortals from './StayPortals'
|
||||
import ChargingInfo from './ChargingInfo'
|
||||
import StopPhoto from './StopPhoto'
|
||||
import { useTranslation } from '../../i18n/TranslationContext'
|
||||
import { useTripStore } from '../../store/tripStore'
|
||||
import { safeExternalHref } from '../../utils/safeUrl'
|
||||
import { StopKindChips, StopStayChips } from './StopChips'
|
||||
import type { CorridorPoi } from './useCorridorPois'
|
||||
@@ -94,6 +96,10 @@ export default function RoadtripStopPopup({
|
||||
const [night, setNight] = useState<boolean>(() => nightByDefault(draft))
|
||||
const [checkIn, setCheckIn] = useState(() => checkInByDefault(draft))
|
||||
const labelId = useId()
|
||||
// A stop already on the trip shows its picture in place of the kind's tile (#2629); a
|
||||
// hit from the search is not a place yet and keeps the tile.
|
||||
const editedPlaceId = draft?.editing?.placeId
|
||||
const place = useTripStore(s => (editedPlaceId == null ? null : s.places.find(p => p.id === editedPlaceId) ?? null))
|
||||
|
||||
// The popup stays mounted while the draft is swapped for another one, so every
|
||||
// answer is seeded again from the new draft, the way the phone sheet does it.
|
||||
@@ -137,12 +143,18 @@ export default function RoadtripStopPopup({
|
||||
header={(
|
||||
<DialogHeader
|
||||
tile={(
|
||||
<DialogTile>
|
||||
{/* The road-trip palette, the same one the map pin and the result row use. */}
|
||||
<span style={{ color: tone }}>
|
||||
{kind ? <kind.Icon size={20} strokeWidth={1.9} aria-hidden /> : <ParkingSquare size={20} strokeWidth={1.9} aria-hidden />}
|
||||
</span>
|
||||
</DialogTile>
|
||||
<StopPhoto
|
||||
place={place}
|
||||
className="h-[46px] w-[46px] flex-none rounded-[14px] bg-surface-card shadow-sm"
|
||||
fallback={(
|
||||
<DialogTile>
|
||||
{/* The road-trip palette, the same one the map pin and the result row use. */}
|
||||
<span style={{ color: tone }}>
|
||||
{kind ? <kind.Icon size={20} strokeWidth={1.9} aria-hidden /> : <ParkingSquare size={20} strokeWidth={1.9} aria-hidden />}
|
||||
</span>
|
||||
</DialogTile>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
tint={NEUTRAL_TINT}
|
||||
labelId={labelId}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { useState, type ReactNode } from 'react';
|
||||
|
||||
import { useTranslation } from '../../i18n';
|
||||
import type { Place } from '../../types';
|
||||
import PlacePhotoGallery from '../Planner/PlacePhotoGallery';
|
||||
import { usePlacePhoto } from '../shared/usePlacePhoto';
|
||||
|
||||
interface StopPhotoProps {
|
||||
/** The trip's place behind the stop; a stop not saved yet has none. */
|
||||
place: Place | null;
|
||||
/** The frame: its size, corners and spacing. The picture fills it. */
|
||||
className: string;
|
||||
/** What stands in while there is no picture. */
|
||||
fallback?: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* A stop's picture on the road (#2629): what helps decide, from the passenger
|
||||
* seat, whether a place is worth the detour. A tap opens the place's photos, the
|
||||
* same gallery the place sheet and the inspector open. A picture that fails to
|
||||
* load gives way to the fallback rather than leaving a broken image behind.
|
||||
*/
|
||||
export default function StopPhoto({ place, className, fallback = null }: StopPhotoProps) {
|
||||
const { t, language } = useTranslation();
|
||||
const photo = usePlacePhoto(place);
|
||||
const [broken, setBroken] = useState<string | null>(null);
|
||||
|
||||
if (!place || !photo || photo === broken) return <>{fallback}</>;
|
||||
// The corners are the frame's, inherited all the way down, so the focus ring of the
|
||||
// gallery trigger follows the picture whatever shape the caller gave it.
|
||||
return (
|
||||
<div className={className}>
|
||||
<PlacePhotoGallery
|
||||
place={place}
|
||||
language={language}
|
||||
label={t('places.openPhotos')}
|
||||
className="h-full w-full rounded-[inherit]"
|
||||
>
|
||||
<img
|
||||
src={photo}
|
||||
alt=""
|
||||
decoding="async"
|
||||
onError={() => setBroken(photo)}
|
||||
className="block h-full w-full rounded-[inherit] object-cover"
|
||||
/>
|
||||
</PlacePhotoGallery>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user