diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json index 0c54f2796..8bab0af42 100644 --- a/client/scripts/feature-pairs.json +++ b/client/scripts/feature-pairs.json @@ -1018,6 +1018,8 @@ "src/mobile/screens/settings/MSettingsUi.tsx": "Phone only settings UI primitives (card, row, input, button, segments, hint).", "src/mobile/screens/settings/MTileCacheUsage.tsx": "Phone only: the native tile cache size and clear action, which the browser build has no counterpart for.", "src/mobile/screens/settings/MWebPushCard.tsx": "Already shares hooks/useWebPush with components/Settings/WebPushCard.tsx.", + "src/mobile/screens/trip/MTripRail.tsx": "Phone shell only; the trip's sections on the leading edge of a wide window in place of the dock, with the tabs and handlers MTripShell hands in.", + "src/mobile/screens/trip/MTripShellParts.tsx": "Markup only; small pieces of MTripShell's top controls (segment pill, compact toggle, document sync button), with the state and handlers MTripShell hands in.", "src/mobile/screens/trip/dockTabs.ts": "Phone only helper that picks which trip tabs get a seat in the mobile dock.", "src/mobile/screens/trip/lib/dayNotes.ts": "Phone only helper that splits a leading time off a day note for the plan timeline.", "src/mobile/screens/trip/map/MMapArea.tsx": "Phone map stage framing; already shares usePoiExplore and useMergedMapPois with the desktop trip planner.", diff --git a/client/scripts/rtl-baseline.json b/client/scripts/rtl-baseline.json index 1ee1892cb..c57ded24b 100644 --- a/client/scripts/rtl-baseline.json +++ b/client/scripts/rtl-baseline.json @@ -87,7 +87,6 @@ "mobile/screens/trip/map/MMapArea.tsx": 3, "mobile/screens/trip/tabs/MCollabPolls.tsx": 1, "mobile/screens/trip/tabs/MFileLightbox.tsx": 2, - "mobile/screens/vacay/MVacay.tsx": 1, "mobile/screens/vacay/MVacayMonth.tsx": 1, "pages/AtlasPage.tsx": 2, "pages/JourneyDetailPage.tsx": 1, diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.json index bf73a550e..d5cf76cf4 100644 --- a/client/scripts/size-baseline.json +++ b/client/scripts/size-baseline.json @@ -5,7 +5,7 @@ "src/components/Admin/AdminPluginsPanel.tsx": 1266, "src/components/Budget/CostsPanel.test.tsx": 2730, "src/components/Budget/CostsPanel.tsx": 1798, - "src/components/Map/MapView.tsx": 1214, + "src/components/Map/MapView.tsx": 1202, "src/components/Map/MapViewGL.test.tsx": 2919, "src/components/Map/MapViewGL.tsx": 2127, "src/components/Planner/DayDetailPanel.test.tsx": 2333, diff --git a/client/scripts/theme-baseline.json b/client/scripts/theme-baseline.json index d7eeccb32..675191e2f 100644 --- a/client/scripts/theme-baseline.json +++ b/client/scripts/theme-baseline.json @@ -40,7 +40,7 @@ "components/Journey/JourneyDetailPageProviderPicker.tsx": 163, "components/Journey/JourneyDetailPageScrollTrigger.tsx": 4, "components/Journey/JourneyDetailPageVerdictSection.tsx": 51, - "components/Journey/JourneyEntryCover.tsx": 15, + "components/Journey/JourneyEntryCover.tsx": 13, "components/Journey/JourneyMap.tsx": 3, "components/Journey/JourneyMapGL.tsx": 5, "components/Journey/MobileEntryView.tsx": 94, diff --git a/client/src/components/Journey/JourneyEntryCover.tsx b/client/src/components/Journey/JourneyEntryCover.tsx index 1f5934ff9..38ea2bab3 100644 --- a/client/src/components/Journey/JourneyEntryCover.tsx +++ b/client/src/components/Journey/JourneyEntryCover.tsx @@ -62,6 +62,11 @@ interface Props { /** The public journey page serves photos through a share token. */ photoUrlFor?: (photoId: number) => string tone?: 'app' | 'mobile' + /** + * large: the card a wide window shows (an iPad, a foldable unfolded), with + * the room for a two-line name and the whole place under it. + */ + size?: 'regular' | 'large' } export default function JourneyEntryCover({ @@ -73,7 +78,9 @@ export default function JourneyEntryCover({ showWeather = true, photoUrlFor, tone = 'app', + size = 'regular', }: Props) { + const large = size === 'large' const { t, locale } = useTranslation() const isSuggestion = entry.type === 'skeleton' @@ -108,7 +115,9 @@ export default function JourneyEntryCover({ // growing its box moved every card after it once a swipe had landed, and the // snap then pulled the strip again, which read as a jolt (carousels keep the // room for it with their gap and top padding). - className={`relative h-[152px] w-[136px] flex-none origin-bottom overflow-hidden rounded-[18px] text-start transition-[transform,box-shadow] duration-200 ease-[cubic-bezier(.2,.8,.2,1)] motion-reduce:transition-none ${ + // White on the root: every mark and line on the card is white, over a photo or + // over the day's colour alike. + className={`relative text-white ${large ? 'h-[196px] w-[176px]' : 'h-[152px] w-[136px]'} flex-none origin-bottom overflow-hidden rounded-[18px] text-start transition-[transform,box-shadow] duration-200 ease-[cubic-bezier(.2,.8,.2,1)] motion-reduce:transition-none ${ isActive ? 'z-[1] scale-[1.18] shadow-[0_18px_40px_-16px_rgba(0,0,0,.55)]' : 'scale-100 shadow-[0_10px_24px_-14px_rgba(0,0,0,.5)]' } ${src ? '' : emptyGround} ${isSuggestion ? 'opacity-90' : ''}`} // backgroundImage, not background: the shorthand would drop the opaque colour @@ -122,7 +131,9 @@ export default function JourneyEntryCover({ // ring lost its top edge to that clip. style={{ boxShadow: `inset 0 0 0 ${isActive ? 2.5 : 1.5}px ${dayColor}${isActive ? '' : 'b3'}`, - ...(src ? null : { backgroundImage: `linear-gradient(160deg, ${dayColor}2e, ${dayColor}0d)` }), + // Without a photograph the card is the day's colour, deep enough to carry + // the white name like a photo does, rather than a grey that read as empty. + ...(src ? null : { backgroundImage: `linear-gradient(160deg, ${dayColor}d9, ${dayColor}8c 55%, ${dayColor}59)` }), }} > {src ? ( @@ -130,8 +141,8 @@ export default function JourneyEntryCover({ ) : ( {posterless - ? - : } + ? + : } )} @@ -155,7 +166,7 @@ export default function JourneyEntryCover({ italic, dimmed title carries the rest. */} {isSuggestion && ( @@ -172,7 +183,7 @@ export default function JourneyEntryCover({ )} {weather && ( - + )} @@ -181,11 +192,11 @@ export default function JourneyEntryCover({ {/* Bottom: the name gets the room the thumbnail layout never had. */} - + {title} {place && ( - + {place} )} diff --git a/client/src/components/Map/ContainerResizeWatcher.test.tsx b/client/src/components/Map/ContainerResizeWatcher.test.tsx new file mode 100644 index 000000000..f1e507ac7 --- /dev/null +++ b/client/src/components/Map/ContainerResizeWatcher.test.tsx @@ -0,0 +1,59 @@ +import { render } from '@testing-library/react'; +import { afterEach, describe, expect, it, vi } from 'vitest'; + +// FE-MAP-RESIZE-001 onwards + +const map = vi.hoisted(() => ({ + container: {} as HTMLElement, + invalidateSize: vi.fn(), + getContainer: vi.fn(), + getCenter: vi.fn(() => ({ lat: 35, lng: 135.7 })), + getZoom: vi.fn(() => 12), + whenReady: vi.fn((fn: () => void) => fn()), + on: vi.fn(), + off: vi.fn(), +})); +vi.mock('react-leaflet', () => ({ useMap: () => map })); + +import ContainerResizeWatcher, { MapCameraSnapshot } from './ContainerResizeWatcher'; + +const realObserver = globalThis.ResizeObserver; + +describe('ContainerResizeWatcher', () => { + afterEach(() => { + globalThis.ResizeObserver = realObserver; + vi.clearAllMocks(); + }); + + it('FE-MAP-RESIZE-001: the map measures itself again whenever its box changes size', () => { + const element = document.createElement('div'); + map.getContainer.mockReturnValue(element); + let fire: () => void = () => {}; + const observe = vi.fn(); + const disconnect = vi.fn(); + globalThis.ResizeObserver = class { + constructor(cb: () => void) { + fire = cb; + } + observe = observe; + unobserve = vi.fn(); + disconnect = disconnect; + } as unknown as typeof ResizeObserver; + + const { unmount } = render(); + expect(observe).toHaveBeenCalledWith(element); + fire(); + expect(map.invalidateSize).toHaveBeenCalledWith(); + unmount(); + expect(disconnect).toHaveBeenCalled(); + }); + + it('FE-MAP-RESIZE-002: the camera snapshot reports where the map looks and stops on unmount', () => { + const onChange = vi.fn(); + const { unmount } = render(); + expect(onChange).toHaveBeenCalledWith([35, 135.7], 12); + expect(map.on).toHaveBeenCalledWith('moveend zoomend', expect.any(Function)); + unmount(); + expect(map.off).toHaveBeenCalledWith('moveend zoomend', expect.any(Function)); + }); +}); diff --git a/client/src/components/Map/ContainerResizeWatcher.tsx b/client/src/components/Map/ContainerResizeWatcher.tsx new file mode 100644 index 000000000..b38a514b4 --- /dev/null +++ b/client/src/components/Map/ContainerResizeWatcher.tsx @@ -0,0 +1,38 @@ +import { useEffect } from 'react'; +import { useMap } from 'react-leaflet'; + +/** + * Leaflet measures its container on window resizes only. The touch shell on a + * wide window resizes the map without one: the trip's plan pane opens and + * closes beside it, and a foldable folds. Without a fresh measure the map kept + * its old size, with grey bands or tiles cut off at the old edge. + */ +export default function ContainerResizeWatcher() { + const map = useMap(); + useEffect(() => { + if (typeof ResizeObserver === 'undefined') return; + // Leaflet's default keeps the centre where it was, so what the map framed stays + // in the middle of the room it now has. + const observer = new ResizeObserver(() => map.invalidateSize()); + observer.observe(map.getContainer()); + return () => observer.disconnect(); + }, [map]); + return null; +} + +/** Reports where the map looks after every move, so a remount can come back to it. */ +export function MapCameraSnapshot({ onChange }: { onChange: (center: [number, number], zoom: number) => void }) { + const map = useMap(); + useEffect(() => { + const save = () => { + const center = map.getCenter(); + onChange([center.lat, center.lng], map.getZoom()); + }; + map.whenReady(save); + map.on('moveend zoomend', save); + return () => { + map.off('moveend zoomend', save); + }; + }, [map, onChange]); + return null; +} diff --git a/client/src/components/Map/MapView.tsx b/client/src/components/Map/MapView.tsx index fb89a3196..605aabd58 100644 --- a/client/src/components/Map/MapView.tsx +++ b/client/src/components/Map/MapView.tsx @@ -2,6 +2,7 @@ import { useEffect, useRef, useState, useMemo, useCallback, memo, type Component import DOM from 'react-dom' import { categoryIconSvg } from './categoryIconSvg' import { MapContainer, TileLayer, Marker, Polyline, CircleMarker, Circle, useMap, Tooltip } from 'react-leaflet' +import ContainerResizeWatcher, { MapCameraSnapshot } from './ContainerResizeWatcher' import MarkerClusterGroup from 'react-leaflet-cluster' import { makeMarkerDraggable } from './markerDrag' import { CLUSTER_OPTIONS, createClusterIcon, revealInCluster, type ClusterGroupLike } from './markerCluster' @@ -244,20 +245,6 @@ function CameraHoverGuard({ movingRef, onMoveStart, onZoom }: { movingRef: { cur return null } -function MapCameraSnapshot({ onChange }: { onChange: (center: [number, number], zoom: number) => void }) { - const map = useMap() - useEffect(() => { - const save = () => { - const center = map.getCenter() - onChange([center.lat, center.lng], map.getZoom()) - } - map.whenReady(save) - map.on('moveend zoomend', save) - return () => { map.off('moveend zoomend', save) } - }, [map, onChange]) - return null -} - interface MapControllerProps { center: [number, number] zoom: number @@ -952,6 +939,7 @@ export const MapView = memo(function MapView({ {/* First, so a fit or a camera request in the same commit starts from the trip's world copy. */} + {hasViewBaseLayer && } 0 ? dayPlaces : places} routeCoords={dayPlaces.length > 0 ? routeCoords : []} fitKey={fitKey} paddingOpts={paddingOpts} framedOnMount={initialView.framed} focusPoints={focusPoints} focusKey={focusKey} fitPadding={fitPadding} follow={followSelection} /> diff --git a/client/src/hooks/sizeClass.ts b/client/src/hooks/sizeClass.ts new file mode 100644 index 000000000..84a48357a --- /dev/null +++ b/client/src/hooks/sizeClass.ts @@ -0,0 +1,59 @@ +import { useSyncExternalStore } from 'react'; + +/** + * The touch shell's size classes, the web's answer to UIKit's compact and + * regular widths. + * + * compact every phone, upright or on its side, and the narrow Split View and + * Stage Manager windows. The shell as it has always been: the dock at + * the bottom, sheets rising from below, one column. + * wide from 600pt across and taller than a phone on its side: an iPad in + * any orientation or window above a third of the screen, a foldable + * unfolded. A navigation rail on the leading edge takes the dock's + * place, sheets become centred form sheets, lists get columns. + * split from 900pt across: room for two panes, so the trip's plan sits next + * to its map and settings show their sections beside the page. + * + * The height bound keeps a phone on its side compact: no phone is taller than + * 500pt in landscape, no tablet or unfolded foldable is shorter. + * + * `tailwind.config.js` registers the same two queries as the `wide:` and + * `split:` variants, and `index.css` reads them for the shell's own variables; + * keep the three in step (sizeClass.test.ts holds them together). + */ +export const WIDE_QUERY = '(min-width: 600px) and (min-height: 501px)'; +export const SPLIT_QUERY = '(min-width: 900px) and (min-height: 501px)'; + +function matches(query: string): boolean { + return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(query).matches; +} + +function subscribe(query: string) { + return (onChange: () => void) => { + if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}; + const mq = window.matchMedia(query); + mq.addEventListener('change', onChange); + return () => mq.removeEventListener('change', onChange); + }; +} + +const subscribeWide = subscribe(WIDE_QUERY); +const subscribeSplit = subscribe(SPLIT_QUERY); +const readWide = () => matches(WIDE_QUERY); +const readSplit = () => matches(SPLIT_QUERY); +const never = () => false; + +/** Whether the touch shell is laid out for a wide window right now, outside React. */ +export function isWideViewport(): boolean { + return readWide(); +} + +/** True while the window is in the wide size class. Follows rotation, folding and resizing. */ +export function useIsWide(): boolean { + return useSyncExternalStore(subscribeWide, readWide, never); +} + +/** True while the window has room for two panes side by side. */ +export function useIsSplit(): boolean { + return useSyncExternalStore(subscribeSplit, readSplit, never); +} diff --git a/client/src/mobile/MobileShell.tsx b/client/src/mobile/MobileShell.tsx index 2b7cd3704..af6b25037 100644 --- a/client/src/mobile/MobileShell.tsx +++ b/client/src/mobile/MobileShell.tsx @@ -3,6 +3,10 @@ import { useMatch } from 'react-router' import BottomNav from '../components/Layout/BottomNav' import ErrorBoundary from '../components/shared/ErrorBoundary' import MBottomNav from './components/MBottomNav' +import MNavRail from './components/MNavRail' +import { useIsWide } from '../hooks/sizeClass' +import MKeyboardHost from './keyboard/MKeyboardHost' +import MShellShortcuts from './keyboard/MShellShortcuts' import MToastHost from './components/MToastHost' import MEdgeBack from './components/MEdgeBack' import { useNativeCapabilities } from '../native/capabilities' @@ -39,6 +43,9 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) { const { caps } = useNativeCapabilities() const pageRef = useRef(null) const edgeBack = isNativeIos() && caps.features.includes('edgeBack') + // On a wide window (an iPad, a foldable unfolded) the rail on the leading edge + // replaces the dock, and the page column starts after it. + const wide = useIsWide() if (!isPhone) { return ( @@ -52,7 +59,7 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) { return ( // min-h-svh, not min-h-dvh: dvh grows while Safari's toolbar retracts, so a // dvh page length would chase the animation it just triggered. -
+
{/* Background and screen gradient live on their own viewport-sized layer. The shell root is as tall as the document now, and --m-scr is a radial gradient measured against its element box, so on it the light cone would @@ -66,10 +73,17 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) { layer to be visible, body must not paint over it, which index.css handles for this breakpoint. */}
-
{children}
+
{children}
- {!inTripPlanner && } + {!inTripPlanner && ( + {wide ? : } + )} + {/* A hardware keyboard (an iPad's, mostly) gets the shortcuts an iPad app has. */} + + + +
) diff --git a/client/src/mobile/components/MGlassBar.tsx b/client/src/mobile/components/MGlassBar.tsx index 455bb5724..5669a281f 100644 --- a/client/src/mobile/components/MGlassBar.tsx +++ b/client/src/mobile/components/MGlassBar.tsx @@ -12,7 +12,7 @@ export default function MGlassBar({ floating = true, className = '', children }: return (
{children} diff --git a/client/src/mobile/components/MNavRail.tsx b/client/src/mobile/components/MNavRail.tsx new file mode 100644 index 000000000..f21fc5304 --- /dev/null +++ b/client/src/mobile/components/MNavRail.tsx @@ -0,0 +1,114 @@ +import type { LucideIcon } from 'lucide-react'; +import { Plus, Search, Settings2, Shield, Sparkles, Upload } from 'lucide-react'; +import { useLocation, useNavigate } from 'react-router'; +import { useAssistantHomeLauncher } from '../../components/Assistant/useAssistantHome'; +import { useNavItems } from '../../components/Layout/navItems'; +import { isNavItemActive, useCreateAction } from '../../components/Layout/useCreateAction'; +import { useTranslation } from '../../i18n'; +import { useAuthStore } from '../../store/authStore'; +import MFab from './MFab'; +import { MRail, MRailButton, MRailSpacer } from './MRail'; + +interface RailEntry { + id: string; + label: string; + icon: LucideIcon; + active: boolean; + go: () => void; +} + +/** + * The touch shell's navigation on a wide window (hooks/sizeClass.ts): a glass + * rail on the leading edge, where an iPad app keeps its sidebar, in place of + * the phone's bottom dock. + * + * It has the room the dock lacks, so every destination sits in it at once, + * with its name under the icon: the dock's own items, the ones the phone keeps + * under More, the home assistant, and settings and administration at the foot, + * which the phone reaches through the avatar menu. The create action keeps the + * dock's raised circle at the head, with the same context-aware meaning. + */ +export default function MNavRail() { + const { t } = useTranslation(); + const navigate = useNavigate(); + const location = useLocation(); + const create = useCreateAction(true); + const assistant = useAssistantHomeLauncher(); + const isAdmin = useAuthStore((s) => s.user?.role === 'admin'); + const navItems = useNavItems(); + + const isActive = (to: string) => isNavItemActive(location.pathname, to); + const main: RailEntry[] = [ + ...navItems.map(({ to, label, icon }) => ({ + id: to, + label, + icon, + active: isActive(to), + go: () => void navigate(to), + })), + ...(assistant.available + ? [{ id: 'assistant', label: t('assistant.launcher.tooltip'), icon: Sparkles, active: false, go: assistant.open }] + : []), + ]; + const foot: RailEntry[] = [ + { + id: '/settings', + label: t('nav.bottomSettings'), + icon: Settings2, + active: isActive('/settings'), + go: () => void navigate('/settings'), + }, + ...(isAdmin + ? [ + { + id: '/admin', + label: t('nav.bottomAdmin'), + icon: Shield, + active: isActive('/admin'), + go: () => void navigate('/admin'), + }, + ] + : []), + ]; + + // Settings and admin have nothing to create, and /vacay draws its own action + // (the year/edit toggle), the same exceptions the dock makes. + const noFab = ['/settings', '/admin', '/vacay'].some((p) => location.pathname.startsWith(p)); + const searchFab = location.pathname.startsWith('/atlas'); + + return ( + + {!noFab && ( + + {searchFab ? ( + + ) : create.upload ? ( + + ) : ( + + )} + + )} + {main.map((entry) => ( + + ))} + +