mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
fix(client): a phone turned sideways stays in the phone layout
The phone shell was chosen by width alone, and most phones are wider than 767px in landscape, so turning one swapped the whole route tree for the desktop planner and an open sheet, its input and the map position were lost. The phone query now also covers a touch screen under 500px tall, which no tablet is. It lives in one place: the shell, the planner and todo hooks, the warnings banner, dialog focus and the stylesheets read it, and six components that measured the window once on mount now follow it.
This commit is contained in:
@@ -76,7 +76,7 @@ interface PlaceFormModalProps {
|
||||
dayAssignments?: Assignment[]
|
||||
/** Mobile keeps the untouched single-column form; desktop adds the saved-place
|
||||
* picker column when the Collections addon is enabled. Sourced from the trip
|
||||
* planner's matchMedia('(max-width:767px)'). */
|
||||
* planner's useIsPhone(). */
|
||||
isMobile?: boolean
|
||||
/** Opens the Costs editor for this place's linked expense (#1298) — the same
|
||||
* seam the booking and transport modals use. */
|
||||
|
||||
@@ -15,6 +15,7 @@ import { useSettingsStore } from '../../store/settingsStore'
|
||||
import { splitReservationDateTime, formatTime } from '../../utils/formatters'
|
||||
import { TransitTitle, TransitMetaBadges, TransitWalkDivider, fmtTransitDuration } from './transitDisplay'
|
||||
import type { Reservation } from '../../types'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
|
||||
/**
|
||||
* The journey view for an automated public-transit entry (#1065): a roomy modal
|
||||
@@ -52,7 +53,7 @@ interface TransitJourneyModalProps {
|
||||
|
||||
export default function TransitJourneyModal({ reservation, onClose, onSave, onDelete, onChangeRoute, onEditDetails, canEdit }: TransitJourneyModalProps) {
|
||||
const { t, locale } = useTranslation()
|
||||
const isMobile = typeof window !== 'undefined' && window.innerWidth < 768
|
||||
const isMobile = useIsPhone()
|
||||
const timeFormat = useSettingsStore(st => st.settings.time_format) || '24h'
|
||||
const res = reservation
|
||||
const meta = typeof res.metadata === 'string' ? (() => { try { return JSON.parse(res.metadata || '{}') } catch { return {} } })() : (res.metadata || {})
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { Day, Place, Accommodation, Reservation } from '../../types'
|
||||
import { useTripStore } from '../../store/tripStore'
|
||||
import { isCarrierTransport } from '../../utils/dayMerge'
|
||||
import type { TransitProvider } from '@trek/shared'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
|
||||
/**
|
||||
* Public transit route search (#1065), backed by Transitous (MOTIS) through the
|
||||
@@ -465,7 +466,7 @@ export default function TransitSearchPanel({ day, days, places, accommodations =
|
||||
const { t, language } = useTranslation()
|
||||
const toast = useToast()
|
||||
const is12h = useSettingsStore(s => s.settings.time_format) === '12h'
|
||||
const isMobile = typeof window !== 'undefined' && window.innerWidth < 768
|
||||
const isMobile = useIsPhone()
|
||||
|
||||
const [from, setFrom] = useState<PickedPlace | null>(initialFrom)
|
||||
const [to, setTo] = useState<PickedPlace | null>(initialTo)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { server } from '../../../tests/helpers/msw/server';
|
||||
import { usePluginStore, type ActivePlugin } from '../../store/pluginStore';
|
||||
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
||||
import TripWarningsBanner from './TripWarningsBanner';
|
||||
import { PHONE_QUERY } from '../../mobile/useIsPhone';
|
||||
|
||||
type Warning = { pluginId: string; level: 'info' | 'warning' | 'error'; message: string };
|
||||
|
||||
@@ -28,12 +29,15 @@ function mountNavSlot(): HTMLElement {
|
||||
return slot;
|
||||
}
|
||||
|
||||
/** matchMedia is stubbed to matches:false globally — opt this component into desktop. */
|
||||
function stubDesktop(matches: boolean) {
|
||||
/**
|
||||
* The banner asks the phone query, so a desktop viewport is one where it does
|
||||
* not match. `fire(true)` means "now desktop", like the old min-width stub.
|
||||
*/
|
||||
function stubDesktop(desktop: boolean) {
|
||||
const listeners: Array<(e: MediaQueryListEvent) => void> = [];
|
||||
const mql = {
|
||||
matches,
|
||||
media: '(min-width: 768px)',
|
||||
matches: !desktop,
|
||||
media: PHONE_QUERY,
|
||||
onchange: null,
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
@@ -42,7 +46,7 @@ function stubDesktop(matches: boolean) {
|
||||
dispatchEvent: vi.fn(() => true),
|
||||
};
|
||||
window.matchMedia = vi.fn(() => mql) as unknown as typeof window.matchMedia;
|
||||
return { mql, fire: (m: boolean) => listeners.forEach(cb => cb({ matches: m } as MediaQueryListEvent)) };
|
||||
return { mql, fire: (desktopNow: boolean) => listeners.forEach(cb => cb({ matches: !desktopNow } as MediaQueryListEvent)) };
|
||||
}
|
||||
|
||||
const originalMatchMedia = window.matchMedia;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createPortal } from 'react-dom'
|
||||
import { AlertTriangle, Info, AlertCircle } from 'lucide-react'
|
||||
import { pluginsApi } from '../../api/client'
|
||||
import { usePluginStore } from '../../store/pluginStore'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
|
||||
/**
|
||||
* Shows validation/warning contributions from `warningProvider` plugins (#1429).
|
||||
@@ -25,9 +26,7 @@ const STYLE = {
|
||||
export default function TripWarningsBanner({ tripId, onOpenPluginTab }: { tripId: number; onOpenPluginTab?: (pluginId: string) => void }) {
|
||||
const [warnings, setWarnings] = useState<Warning[]>([])
|
||||
const [navSlot, setNavSlot] = useState<HTMLElement | null>(null)
|
||||
const [isDesktop, setIsDesktop] = useState(
|
||||
() => typeof window !== 'undefined' && (window.matchMedia?.('(min-width: 768px)')?.matches ?? true)
|
||||
)
|
||||
const isDesktop = !useIsPhone()
|
||||
const plugins = usePluginStore((s) => s.plugins)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -42,13 +41,6 @@ export default function TripWarningsBanner({ tripId, onOpenPluginTab }: { tripId
|
||||
// The navbar renders in the same commit as the planner, so the slot exists by
|
||||
// the time effects run; it is display:none'd with the navbar below md.
|
||||
useEffect(() => { setNavSlot(document.getElementById('trek-nav-center-slot')) }, [])
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia?.('(min-width: 768px)')
|
||||
if (!mq) return
|
||||
const handler = (e: MediaQueryListEvent) => setIsDesktop(e.matches)
|
||||
mq.addEventListener('change', handler)
|
||||
return () => mq.removeEventListener('change', handler)
|
||||
}, [])
|
||||
|
||||
if (warnings.length === 0) return null
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react'
|
||||
import { Footprints, MoveRight, type LucideIcon } from 'lucide-react'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
|
||||
/**
|
||||
* Shared display bits for public-transit entries (#1065) — the timeline row,
|
||||
@@ -33,7 +34,7 @@ export function TransitWalkDivider({ leg, t, size = 'md' }: {
|
||||
size?: 'sm' | 'md'
|
||||
}) {
|
||||
const mins = leg.duration ? Math.round(leg.duration / 60) : null
|
||||
const isMobile = typeof window !== 'undefined' && window.innerWidth < 768
|
||||
const isMobile = useIsPhone()
|
||||
// Hairlines that fade towards the outer edges — strongest next to the text.
|
||||
const rule = (dir: 'left' | 'right'): React.CSSProperties => ({
|
||||
flex: 1, height: 1, minWidth: 12, borderRadius: 1,
|
||||
|
||||
Reference in New Issue
Block a user