The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(mobile): the chat watches its list once it exists, keeps its draft, and the desktop map opens as before
Maurice61d925f3dda1
diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.jsonindex 6dd3e7959..69b0dc228 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": 1202,+ "src/components/Map/MapView.tsx": 1201,"src/components/Map/MapViewGL.test.tsx": 2919,"src/components/Map/MapViewGL.tsx": 2127,"src/components/Planner/DayDetailPanel.test.tsx": 2333,diff --git a/client/src/components/Collab/useCollabChatData.test.ts b/client/src/components/Collab/useCollabChatData.test.tsindex db7fd09a2..d1dba8107 100644--- a/client/src/components/Collab/useCollabChatData.test.ts+++ b/client/src/components/Collab/useCollabChatData.test.ts@@ -1,8 +1,8 @@// FE-COLLAB-CHATDATA-001 to FE-COLLAB-CHATDATA-018: the trip chat logic behind the desktop// Collab panel (quiet older-page errors, scroll on remote delete, upload progress) and the// phone's chat tab (toasted older-page errors, sending gated on the edit permission).-import { act, renderHook, waitFor } from '@testing-library/react';-import type { ChangeEvent } from 'react';+import { act, fireEvent, render, renderHook, screen, waitFor } from '@testing-library/react';+import { createElement, type ChangeEvent } from 'react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { collabApi } from '../../api/client';@@ -289,54 +289,74 @@ describe('useCollabChatData', () => {describe('useCollabChatData on a box that changes size', () => {// The observer reports when the test says the list's box has changed.let report: () => void = () => {};+ let observed: Element[] = [];class Observer {constructor(callback: ResizeObserverCallback) {report = () => callback([], this as unknown as ResizeObserver);}- observe() {}+ observe(el: Element) {+ observed.push(el);+ }unobserve() {}disconnect() {}}- function mountList(scrollHeight: number) {- let scrollTop = 0;- const list = document.createElement('div');- Object.defineProperty(list, 'scrollHeight', { configurable: true, get: () => scrollHeight });- Object.defineProperty(list, 'clientHeight', { configurable: true, get: () => 400 });- Object.defineProperty(list, 'scrollTop', {- configurable: true,- get: () => scrollTop,- set: (v: number) => {- scrollTop = v;- },- });- const hook = renderHook(() => {- const chat = useCollabChatData({- tripId: 1,- t,- toast: { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() },- });- (chat.scrollRef as { current: HTMLDivElement | null }).current = list;- return chat;+ /**+ * The list as both views draw it: only once the messages are in, so at mount there+ * is no element yet. Its sizes are the test's to set, since jsdom lays nothing out.+ */+ function ChatList({ scrollHeight }: { scrollHeight: () => number }) {+ const chat = useCollabChatData({+ tripId: 1,+ t,+ toast: { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() },});- return { hook, list, grow: (to: number) => (scrollHeight = to) };+ const setList = (el: HTMLDivElement | null) => {+ if (el && !Object.getOwnPropertyDescriptor(el, 'scrollHeight')) {+ let scrollTop = 0;+ Object.defineProperty(el, 'scrollHeight', { configurable: true, get: scrollHeight });+ Object.defineProperty(el, 'clientHeight', { configurable: true, get: () => 400 });+ Object.defineProperty(el, 'scrollTop', {+ configurable: true,+ get: () => scrollTop,+ set: (v: number) => {+ scrollTop = v;+ },+ });+ el.scrollTo = () => {};+ }+ (chat.scrollRef as { current: HTMLDivElement | null }).current = el;+ };+ if (chat.loading || chat.messages.length === 0) return createElement('p', null, 'loading');+ return createElement('div', { 'data-testid': 'list', ref: setList, onScroll: chat.checkAtBottom });}+ async function mountList(height: number) {+ let scrollHeight = height;+ render(createElement(ChatList, { scrollHeight: () => scrollHeight }));+ const list = await screen.findByTestId('list');+ return { list, grow: (to: number) => (scrollHeight = to) };+ }++ beforeEach(() => {+ observed = [];+ });afterEach(() => vi.unstubAllGlobals());- it('FE-COLLAB-CHATDATA-017: a list at its newest message stays there when a rotation or a fold resizes it', () => {+ it('FE-COLLAB-CHATDATA-017: a list at its newest message stays there when a rotation or a fold resizes it', async () => {vi.stubGlobal('ResizeObserver', Observer);- const { list, grow } = mountList(400);+ const { list, grow } = await mountList(400);+ expect(observed).toContain(list);grow(900);report();expect(list.scrollTop).toBe(900);});- it('FE-COLLAB-CHATDATA-018: a list read further up keeps its place', () => {+ it('FE-COLLAB-CHATDATA-018: a list read further up keeps its place', async () => {vi.stubGlobal('ResizeObserver', Observer);- const { hook, list, grow } = mountList(2000);+ const { list, grow } = await mountList(2000);list.scrollTop = 200;- hook.result.current.checkAtBottom();+ fireEvent.scroll(list);grow(2600);report();expect(list.scrollTop).toBe(200);diff --git a/client/src/components/Collab/useCollabChatData.ts b/client/src/components/Collab/useCollabChatData.tsindex f47807142..c59eadca1 100644--- a/client/src/components/Collab/useCollabChatData.ts+++ b/client/src/components/Collab/useCollabChatData.ts@@ -79,16 +79,19 @@ export function useCollabChatData({// A list that sat at its newest message stays there when its box changes size (a// rotation, a fold, a pane opening beside it): the messages wrap anew and the list- // grows, which left the newest ones below the composer.+ // grows, which left the newest ones below the composer. Both views draw the list+ // only once there are messages to show, so the observer attaches when it appears,+ // not at mount, when there is nothing yet to observe.+ const listShown = !loading && messages.length > 0;useEffect(() => {const el = scrollRef.current;- if (!el || typeof ResizeObserver === 'undefined') return;+ if (!listShown || !el || typeof ResizeObserver === 'undefined') return;const observer = new ResizeObserver(() => {if (isAtBottom.current) el.scrollTop = el.scrollHeight;});observer.observe(el);return () => observer.disconnect();- }, []);+ }, [listShown]);useEffect(() => {let cancelled = false;diff --git a/client/src/components/Map/MapView.test.tsx b/client/src/components/Map/MapView.test.tsxindex e99ff1a57..b4496cef8 100644--- a/client/src/components/Map/MapView.test.tsx+++ b/client/src/components/Map/MapView.test.tsx@@ -1586,12 +1586,25 @@ describe('MapView bounds fitting', () => {expect(mapMock.fitBounds.mock.calls[2][1]).toMatchObject({ paddingTopLeft: [40, 20], paddingBottomRight: [40, 20] })})- it('FE-COMP-MAPVIEW-094: opens framed at the whole zoom level that fits, not the nearest one', () => {+ it('FE-COMP-MAPVIEW-094: beside the pane the touch shell opens at the whole zoom level that fits; the desktop keeps its own opening', () => {// A day spread so that its exact fit lies between two levels.const places = [buildMapPlace({ id: 1, lat: 34.9671, lng: 135.7727 }), buildMapPlace({ id: 2, lat: 35.005, lng: 135.7649 })]+ shell.phone = true+ setSizeClass('wide')+ const { unmount } = render(<MapView places={places} />)+ const paned = Number(screen.getByTestId('map-container').getAttribute('data-zoom'))+ expect(Number.isInteger(paned)).toBe(true)+ unmount()++ // The desktop planner hands Leaflet the fitted level, which it rounds to the nearest+ // as it always has, and fits no second time.+ shell.phone = false+ setSizeClass('compact')+ mapMock.setView.mockClear()render(<MapView places={places} />)- const zoom = Number(screen.getByTestId('map-container').getAttribute('data-zoom'))- expect(Number.isInteger(zoom)).toBe(true)+ const desk = Number(screen.getByTestId('map-container').getAttribute('data-zoom'))+ expect(Number.isInteger(desk)).toBe(false)+ expect(mapMock.setView).not.toHaveBeenCalled()})it('FE-COMP-MAPVIEW-093: on an iPad the touch shell frames a day clear of its floating toolbar and corner buttons', () => {diff --git a/client/src/components/Map/MapView.tsx b/client/src/components/Map/MapView.tsxindex c4025fce1..52c242f25 100644--- a/client/src/components/Map/MapView.tsx+++ b/client/src/components/Map/MapView.tsx@@ -672,7 +672,6 @@ export const MapView = memo(function MapView({), [reservations, visibleConnectionIds, showTransitRoutes, selectedDayId, days, scopeConnectionsToDay])// Real road geometry for car/bus/taxi/bicycle bookings (straight line until it loads/if it fails).const transportRoutes = useTransportRoutes(visibleReservations)- // Dynamic padding: account for sidebars + bottom inspector + day detail panel// The chrome overlaying the map (side panels, day detail). Kept as a plain box so both the// Leaflet fit options and the opening-camera maths can read the same numbers.// Followed rather than read once: a phone turned sideways and back crosses@@ -698,14 +697,12 @@ export const MapView = memo(function MapView({const paddingOpts = useMemo(() => leafletPadding(paddingBox), [paddingBox])- // Open framed on the places rather than on the caller's default, so a trip in Japan shows- // Japan straight away instead of the world view followed by a flight across the planet.- // The initializer runs once, at mount — exactly when this should be decided; afterwards the- // camera belongs to the user. `framed` is false when no place has coordinates (a new trip),- // and then the caller's center/zoom stands.- const [initialView] = useState(() =>- openingView(dayPlaces.length > 0 ? dayPlaces : places, { padding: paddingBox, lngFrame, center, zoom }),- )+ // Open framed on the places, not on the caller's default: a trip in Japan shows Japan at once instead+ // of the world and a flight across it. Decided once, at mount; afterwards the camera is the user's.+ // `framed` is false when no place has coordinates (a new trip), and then the caller's center/zoom stands.+ const [initialView] = useState(() => openingView(dayPlaces.length > 0 ? dayPlaces : places, {+ padding: paddingBox, lngFrame, center, zoom, paned: isMobile && isWide,+ }))const cameraSnapshotRef = useRef<{ center: [number, number]; zoom: number } | null>(null)const saveCameraSnapshot = useCallback((cameraCenter: [number, number], cameraZoom: number) => {cameraSnapshotRef.current = { center: cameraCenter, zoom: cameraZoom }diff --git a/client/src/components/Map/openingView.ts b/client/src/components/Map/openingView.tsindex 555893981..5a267c60a 100644--- a/client/src/components/Map/openingView.ts+++ b/client/src/components/Map/openingView.ts@@ -3,21 +3,32 @@ import { computeMapViewport, TILE_SIZE_RASTER, type GeoPointish, type ViewportPa/*** Where MapView opens: framed on the places when they have coordinates, else- * at the caller's centre and zoom. Leaflet snaps to whole zoom levels and+ * at the caller's centre and zoom.+ *+ * In the touch shell on a wide window (`paned`), where the map is a part of+ * the window beside the trip's pane: Leaflet snaps to whole zoom levels and* rounds to the nearest, so 14.7 became 15 and the day ran off the map; the* whole level below always fits. `refit` keeps what the frame was worked out* for (the window), so OpeningFrameFit can work it out again for the map's- * own size once it has one.+ * own size once it has one. Everywhere else (the desktop planner, a phone) the+ * map opens as it always has: Leaflet's nearest level, and no second fit.*/export function openingView(points: readonly GeoPointish[],- options: { padding: ViewportPadding; lngFrame: LngFrame | null; center: [number, number]; zoom: number }+ options: {+ padding: ViewportPadding;+ lngFrame: LngFrame | null;+ center: [number, number];+ zoom: number;+ paned?: boolean;+ }): { center: [number, number]; zoom: number; framed: boolean; refit: OpeningFrame | null } {// With a longitude frame the trip lies on one copy, so it can be framed the short way.const wrapsWorld = options.lngFrame !== null;const fitted = computeMapViewport(points, { tileSize: TILE_SIZE_RASTER, padding: options.padding, wrapsWorld });if (!fitted) return { center: options.center, zoom: options.zoom, framed: false, refit: null };const center: [number, number] = [fitted.center[0], frameLng(options.lngFrame, fitted.center[1])];+ if (!options.paned) return { center, zoom: fitted.zoom, framed: true, refit: null };const zoom = Math.floor(fitted.zoom);const width = typeof window !== 'undefined' && window.innerWidth > 0 ? window.innerWidth : 1024;const height = typeof window !== 'undefined' && window.innerHeight > 0 ? window.innerHeight : 768;diff --git a/client/src/mobile/screens/trip/tabs/MCollabTab.tsx b/client/src/mobile/screens/trip/tabs/MCollabTab.tsxindex 99334edd0..672384b15 100644--- a/client/src/mobile/screens/trip/tabs/MCollabTab.tsx+++ b/client/src/mobile/screens/trip/tabs/MCollabTab.tsx@@ -38,12 +38,19 @@ export default function MCollabTab({ planner, shell }: MTabScreenProps) {// The chat keeps its place in the tree either way (a slot that stays empty// still holds its index), so a rotation or a fold that crosses into or out of// two panes keeps the draft and the scroll position instead of remounting it.+ // That holds for a board picked beside it too: turning an iPad upright then+ // leaves the board on its own and only hides the chat, with its half typed+ // message, until the switch brings it back.const sideBySide = collabSideBySide(split, planner.collabFeatures)const board = sideBySide? collabBoardFor(shell.collabTab, planner.collabFeatures): isCollabBoard(shell.collabTab) ? shell.collabTab : nullconst chat = sideBySide || shell.collabTab === 'chat'+ const keepChat = chat || planner.collabFeatures.chatif (!board && !chat) return null+ let chatPane = 'hidden'+ if (sideBySide) chatPane = 'm-pane-trail relative h-full flex-none border-s border-[color:var(--m-rowbr)]'+ else if (chat) chatPane = 'relative h-full min-w-0 flex-1'return (<div className="flex h-full">{board && (@@ -51,12 +58,8 @@ export default function MCollabTab({ planner, shell }: MTabScreenProps) {<CollabPanel planner={planner} tab={board} /></div>)}- {chat && (- <div- className={sideBySide- ? 'm-pane-trail relative h-full flex-none border-s border-[color:var(--m-rowbr)]'- : 'relative h-full min-w-0 flex-1'}- >+ {keepChat && (+ <div className={chatPane}><CollabPanel planner={planner} tab="chat" /></div>)}@@ -98,9 +101,11 @@ function CollabPanel({ planner, tab }: { planner: MTabScreenProps['planner']; ta</TabScroller>)}+ // On a wide window the card is as tall as its links: a page-high card with+ // four rows at its top read as a list that failed to fill.return (<TabScroller>- <div className="min-h-[70vh] overflow-hidden rounded-[18px] bg-[color:var(--m-card)]">+ <div className="min-h-[70vh] overflow-hidden rounded-[18px] bg-[color:var(--m-card)] wide:min-h-0"><CollabLinks tripId={planner.tripId} /></div></TabScroller>diff --git a/client/tests/unit/mobile/trip/MCollabTab.test.tsx b/client/tests/unit/mobile/trip/MCollabTab.test.tsxindex efd6ba0ba..3a8dca8c3 100644--- a/client/tests/unit/mobile/trip/MCollabTab.test.tsx+++ b/client/tests/unit/mobile/trip/MCollabTab.test.tsx@@ -5,7 +5,7 @@ import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'import { render, screen } from '../../../helpers/render'import { setSizeClass } from '../../../helpers/sizeClass'-// FE-MOB-CTAB-001 to FE-MOB-CTAB-012+// FE-MOB-CTAB-001 to FE-MOB-CTAB-013// The three sub-panels are self-contained (own API calls + WebSocket listener)// and covered by their own suites — here only the routing is under test.@@ -35,18 +35,18 @@ describe('MCollabTab', () => {expect(screen.queryByTestId('polls')).not.toBeInTheDocument()})- it('FE-MOB-CTAB-002: routes the notes sub-tab to MCollabNotes', () => {+ it('FE-MOB-CTAB-002: routes the notes sub-tab to MCollabNotes, the chat kept hidden behind it', () => {renderTab('notes')expect(screen.getByTestId('notes')).toBeInTheDocument()- expect(screen.queryByTestId('chat')).not.toBeInTheDocument()+ expect(screen.getByTestId('chat').parentElement).toHaveClass('hidden')})- it('FE-MOB-CTAB-003: routes the polls sub-tab to MCollabPolls', () => {+ it('FE-MOB-CTAB-003: routes the polls sub-tab to MCollabPolls, the chat kept hidden behind it', () => {renderTab('polls')expect(screen.getByTestId('polls')).toBeInTheDocument()- expect(screen.queryByTestId('chat')).not.toBeInTheDocument()+ expect(screen.getByTestId('chat').parentElement).toHaveClass('hidden')})it('FE-MOB-CTAB-004: shows the disabled notice instead of the chat panel', () => {@@ -118,4 +118,20 @@ describe('MCollabTab', () => {expect(screen.queryByTestId('notes')).not.toBeInTheDocument()expect(screen.getByTestId('chat')).toBe(before)})++ it('FE-MOB-CTAB-013: leaving two panes with a board picked keeps the chat beside it, hidden, draft and all', () => {+ setSizeClass('split')+ renderTab('notes')+ const before = screen.getByTestId('chat')+ expect(before.parentElement).not.toHaveClass('hidden')++ setSizeClass('wide')+ expect(screen.getByTestId('notes')).toBeInTheDocument()+ expect(screen.getByTestId('chat')).toBe(before)+ expect(before.parentElement).toHaveClass('hidden')++ setSizeClass('split')+ expect(screen.getByTestId('chat')).toBe(before)+ expect(before.parentElement).not.toHaveClass('hidden')+ })})