diff --git a/client/src/components/Collections/PlacesLibraryView.tsx b/client/src/components/Collections/PlacesLibraryView.tsx index fd0664e8a..0b716ea3b 100644 --- a/client/src/components/Collections/PlacesLibraryView.tsx +++ b/client/src/components/Collections/PlacesLibraryView.tsx @@ -16,6 +16,7 @@ import LibraryFilterBar from './LibraryFilterBar'; import LibraryOrigins from './LibraryOrigins'; import LibraryPlaceDetail from './LibraryPlaceDetail'; import { detailDock } from './detailDock'; +import { saveDraftOf } from './libraryPairs'; import { usePlaceDuplicates } from './usePlaceDuplicates'; import { usePlacesLibrary } from './usePlacesLibrary'; @@ -284,21 +285,7 @@ export default function PlacesLibraryView({ onClose={lib.close} onOpenList={(collectionId, placeId) => navigate(`${placesPath(collectionId)}?place=${placeId}`)} onOpenTrip={(tripId, placeId) => navigate(`/trips/${tripId}?place=${placeId}`)} - onSaveToList={(origin, d) => - openSave({ - name: d.info.name, - source_trip_id: origin.trip_id, - source_place_id: origin.place_id, - description: d.info.description, - lat: d.info.lat, - lng: d.info.lng, - address: d.info.address, - category_id: lib.detail?.entry.category?.id ?? null, - image_url: d.info.image_url, - website: d.info.website, - phone: d.info.phone, - }) - } + onSaveToList={(origin, d) => openSave(saveDraftOf(origin, d, lib.detail?.entry.category?.id))} onCopyToTrip={setCopyId} t={t} /> diff --git a/client/src/components/Collections/libraryPairs.test.ts b/client/src/components/Collections/libraryPairs.test.ts index 2c452a137..7359618fb 100644 --- a/client/src/components/Collections/libraryPairs.test.ts +++ b/client/src/components/Collections/libraryPairs.test.ts @@ -1,4 +1,4 @@ -// FE-COMP-LIBPAIRS-001 to FE-COMP-LIBPAIRS-008 +// FE-COMP-LIBPAIRS-001 to FE-COMP-LIBPAIRS-009 import type { PlacesLibraryDetailResponse } from '@trek/shared'; import { @@ -11,7 +11,7 @@ import { tripDetail, tripOrigin, } from '../../../tests/helpers/placesLibrary'; -import { originPairs } from './libraryPairs'; +import { originPairs, saveDraftOf } from './libraryPairs'; describe('originPairs', () => { it('FE-COMP-LIBPAIRS-001: nothing open gives nothing', () => { @@ -71,4 +71,18 @@ describe('originPairs', () => { it('FE-COMP-LIBPAIRS-008: no description anywhere leaves it undefined', () => { expect(originPairs(bothOrigins()).description).toBeUndefined(); }); + + it('FE-COMP-LIBPAIRS-009: a trip place goes to the save dialog with what the trip keeps and the category', () => { + const origin = tripOrigin({ trip_id: 5, place_id: 8 }); + const detail = tripDetail({ place_id: 8, info: libraryInfo({ name: 'Arena', website: 'https://arena.example' }) }); + const draft = saveDraftOf(origin, detail, 3); + expect(draft).toMatchObject({ + name: 'Arena', + source_trip_id: 5, + source_place_id: 8, + category_id: 3, + website: 'https://arena.example', + }); + expect(saveDraftOf(origin, detail, undefined).category_id).toBeNull(); + }); }); diff --git a/client/src/components/Collections/libraryPairs.ts b/client/src/components/Collections/libraryPairs.ts index 48e1d8dd0..7ecc26ded 100644 --- a/client/src/components/Collections/libraryPairs.ts +++ b/client/src/components/Collections/libraryPairs.ts @@ -26,3 +26,21 @@ export function originPairs(data: PlacesLibraryDetailResponse | null): { description: pairs.map((p) => p.detail.info.description).find((d) => d?.trim()) ?? undefined, }; } + +/** A trip place of an entry, as the "save to a list" dialog takes it: what the trip keeps, the entry's category. */ +export function saveDraftOf(origin: TripOrigin, detail: TripDetail, categoryId: number | null | undefined) { + const info = detail.info; + return { + name: info.name, + source_trip_id: origin.trip_id, + source_place_id: origin.place_id, + description: info.description, + lat: info.lat, + lng: info.lng, + address: info.address, + category_id: categoryId ?? null, + image_url: info.image_url, + website: info.website, + phone: info.phone, + }; +} diff --git a/client/src/mobile/screens/collections/MPlacesLibrary.tsx b/client/src/mobile/screens/collections/MPlacesLibrary.tsx index 7b3bdda8b..a14b49e3e 100644 --- a/client/src/mobile/screens/collections/MPlacesLibrary.tsx +++ b/client/src/mobile/screens/collections/MPlacesLibrary.tsx @@ -16,6 +16,7 @@ import { } from 'lucide-react'; import { useMemo, useState } from 'react'; import CollectionMap from '../../../components/Collections/CollectionMap'; +import { saveDraftOf } from '../../../components/Collections/libraryPairs'; import { originName } from '../../../components/Collections/originName'; import { usePlaceDuplicates } from '../../../components/Collections/usePlaceDuplicates'; import { usePlacesLibrary, type LibraryKindFilter } from '../../../components/Collections/usePlacesLibrary'; @@ -429,21 +430,7 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie onClose={lib.close} onOpenList={(collectionId, placeId) => navigate(`${placesPath(collectionId)}?place=${placeId}`)} onOpenTrip={(tripId, placeId) => navigate(`/trips/${tripId}?place=${placeId}`)} - onSaveToList={(origin, d) => - openSave({ - name: d.info.name, - source_trip_id: origin.trip_id, - source_place_id: origin.place_id, - description: d.info.description, - lat: d.info.lat, - lng: d.info.lng, - address: d.info.address, - category_id: lib.detail?.entry.category?.id ?? null, - image_url: d.info.image_url, - website: d.info.website, - phone: d.info.phone, - }) - } + onSaveToList={(origin, d) => openSave(saveDraftOf(origin, d, lib.detail?.entry.category?.id))} onCopyToTrip={(id) => { lib.close(); setCopyId(id);