mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
feat(mobile): open directions from a place's address and a booking's location
On the road the address is what the eye lands on. A tap on it in the place sheet now does what the navigation button does (the preferred map app, or the choice of apps), and the location row of a booking card opens directions to it the same way, marked by a small arrow. The rest of the booking card still opens the booking. Addresses discussion #3213.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useRef, useState } from 'react'
|
import { useMemo, useRef, useState, type KeyboardEvent } from 'react'
|
||||||
import DawarichIcon from '../../../../components/shared/DawarichIcon'
|
import DawarichIcon from '../../../../components/shared/DawarichIcon'
|
||||||
import {
|
import {
|
||||||
Bookmark, ChevronRight, ExternalLink, Map as MapIcon, MapPinOff, Navigation, Paperclip,
|
Bookmark, ChevronRight, ExternalLink, Map as MapIcon, MapPinOff, Navigation, Paperclip,
|
||||||
@@ -220,8 +220,28 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{/* A tap on the address opens directions, as the navigation button does:
|
||||||
|
on the road the address is what the eye lands on. */}
|
||||||
{place.address && (
|
{place.address && (
|
||||||
<div className="mt-[2px] font-geist text-[0.6875rem] leading-[1.4] text-m-muted"><bdi>{place.address}</bdi></div>
|
<div
|
||||||
|
className={`mt-[2px] font-geist text-[0.6875rem] leading-[1.4] text-m-muted${navTargets.length > 0 ? ' cursor-pointer underline decoration-dotted underline-offset-2' : ''}`}
|
||||||
|
{...(navTargets.length > 0
|
||||||
|
? {
|
||||||
|
role: 'button',
|
||||||
|
tabIndex: 0,
|
||||||
|
'aria-label': `${navTargets.length === 1 ? navigationTargetLabel(navTargets[0], t) : t('inspector.navigation')}: ${place.address}`,
|
||||||
|
onClick: openDirections,
|
||||||
|
onKeyDown: (e: KeyboardEvent) => {
|
||||||
|
if (e.key === 'Enter' || e.key === ' ') {
|
||||||
|
e.preventDefault()
|
||||||
|
openDirections()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {})}
|
||||||
|
>
|
||||||
|
<bdi>{place.address}</bdi>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
{/* A typed address that never got coordinates: no marker, and the sheet says why (#2837). */}
|
{/* A typed address that never got coordinates: no marker, and the sheet says why (#2837). */}
|
||||||
{addressWithoutCoordinates(place) && (
|
{addressWithoutCoordinates(place) && (
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { MapPin } from 'lucide-react'
|
import { MapPin, Navigation } from 'lucide-react'
|
||||||
|
import { useState } from 'react'
|
||||||
import MDancingTrek from '../../../components/MDancingTrek'
|
import MDancingTrek from '../../../components/MDancingTrek'
|
||||||
import { RES_ICONS } from '../../../../components/Planner/DayPlanSidebar.constants'
|
import { RES_ICONS } from '../../../../components/Planner/DayPlanSidebar.constants'
|
||||||
import { formatTime, formatPriceText } from '../../../../utils/formatters'
|
import { formatTime, formatPriceText } from '../../../../utils/formatters'
|
||||||
@@ -13,6 +14,8 @@ import { useReservationListFilter } from '../../../../components/Planner/booking
|
|||||||
import { useReservationCard } from '../../../../components/Planner/bookings/useReservationCard'
|
import { useReservationCard } from '../../../../components/Planner/bookings/useReservationCard'
|
||||||
import { orderedEndpoints, seatCells } from '../../../../utils/flightLegs'
|
import { orderedEndpoints, seatCells } from '../../../../utils/flightLegs'
|
||||||
import { filesFor } from '../../../../utils/reservationFiles'
|
import { filesFor } from '../../../../utils/reservationFiles'
|
||||||
|
import { getNavigationTargets, openNavigationTarget } from '../../../../components/Planner/placeNavigation'
|
||||||
|
import { NavigationMenu } from '../../../../components/shared/NavigationMenu'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tab 2 — Buchungen. Real `planner.reservations` filtered to the non-transport
|
* Tab 2 — Buchungen. Real `planner.reservations` filtered to the non-transport
|
||||||
@@ -176,17 +179,16 @@ function BookingCard({ res, planner, canEdit, compact, onView }: {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<TravelerAvatars travelers={res.travelers || []} label={t('reservations.travelers.label')} />
|
<TravelerAvatars travelers={res.travelers || []} label={t('reservations.travelers.label')} />
|
||||||
|
|
||||||
{res.location && (
|
|
||||||
<div className="mt-2 flex items-center gap-[6px] rounded-[10px] border border-[color:var(--m-rowbr)] bg-m-card px-[10px] py-[7px]">
|
|
||||||
<MapPin size={12} strokeWidth={2} className="flex-none text-m-muted" />
|
|
||||||
<span dir="auto" className="truncate text-[0.71875rem] font-semibold text-m-ink">{res.location}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<CardNotes notes={res.notes} />
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<CardLocation location={res.location} />
|
||||||
|
|
||||||
|
{res.notes?.trim() && (
|
||||||
|
<button type="button" onClick={onView} className="block w-full text-start">
|
||||||
|
<CardNotes notes={res.notes} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
<CardFiles files={files} card={card} t={t} />
|
<CardFiles files={files} card={card} t={t} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -196,3 +198,40 @@ function BookingCard({ res, planner, canEdit, compact, onView }: {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where the booking is (the hotel, the rental desk): a tap opens directions to
|
||||||
|
* it, as the address of a place does, in the traveller's map app or with the
|
||||||
|
* same choice of apps.
|
||||||
|
*/
|
||||||
|
function CardLocation({ location }: { location: string | null | undefined }) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const [anchor, setAnchor] = useState<HTMLButtonElement | null>(null)
|
||||||
|
const [menuOpen, setMenuOpen] = useState(false)
|
||||||
|
const text = location?.trim()
|
||||||
|
if (!text) return null
|
||||||
|
const targets = getNavigationTargets({ name: text, address: text, lat: null, lng: null, google_place_id: null, google_ftid: null })
|
||||||
|
const openDirections = () => {
|
||||||
|
if (targets.length === 1) openNavigationTarget(targets[0])
|
||||||
|
else if (targets.length > 1) setMenuOpen(true)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
ref={setAnchor}
|
||||||
|
type="button"
|
||||||
|
onClick={openDirections}
|
||||||
|
disabled={targets.length === 0}
|
||||||
|
aria-label={`${t('inspector.navigation')}: ${text}`}
|
||||||
|
className="mt-2 flex w-full items-center gap-[6px] rounded-[10px] border border-[color:var(--m-rowbr)] bg-m-card px-[10px] py-[7px] text-start"
|
||||||
|
>
|
||||||
|
<MapPin size={12} strokeWidth={2} className="flex-none text-m-muted" />
|
||||||
|
<span dir="auto" className="min-w-0 flex-1 truncate text-[0.71875rem] font-semibold text-m-ink">{text}</span>
|
||||||
|
{targets.length > 0 && <Navigation size={12} strokeWidth={2} aria-hidden="true" className="flex-none text-m-muted" />}
|
||||||
|
</button>
|
||||||
|
{menuOpen && (
|
||||||
|
<NavigationMenu targets={targets} anchor={anchor} onClose={() => setMenuOpen(false)} title={t('inspector.openWith')} />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user