diff --git a/client/src/components/Collections/CollectionPicker.test.tsx b/client/src/components/Collections/CollectionPicker.test.tsx index 8a1be5133..75487f1b2 100644 --- a/client/src/components/Collections/CollectionPicker.test.tsx +++ b/client/src/components/Collections/CollectionPicker.test.tsx @@ -53,6 +53,50 @@ describe('CollectionPicker', () => { vi.restoreAllMocks() }) + it('FE-COMP-COLPICKER-017: shows the first ten and offers the rest behind a button', async () => { + // Saved places accumulate across every list, so the panel used to scroll + // without end. + const many = Array.from({ length: 23 }, (_, i) => + place({ id: 100 + i, collection_id: 1, name: `Place ${String(i).padStart(2, '0')}` }), + ) + vi.spyOn(collectionsApi, 'get').mockImplementation(async (id: number) => + id === 1 ? detail(listA, many) : detail(listB, []), + ) + setup() + + expect(await screen.findByText('Place 00')).toBeInTheDocument() + expect(screen.getByText('Place 09')).toBeInTheDocument() + expect(screen.queryByText('Place 10')).not.toBeInTheDocument() + + const more = () => screen.getByRole('button', { name: /show .* more/i }) + fireEvent.click(more()) + expect(screen.getByText('Place 19')).toBeInTheDocument() + expect(screen.queryByText('Place 20')).not.toBeInTheDocument() + + fireEvent.click(more()) + expect(screen.getByText('Place 22')).toBeInTheDocument() + // Nothing left to ask for. + expect(screen.queryByRole('button', { name: /more/i })).not.toBeInTheDocument() + }) + + it('FE-COMP-COLPICKER-018: searching resets the page and looks at every place, not just the visible ten', async () => { + const many = Array.from({ length: 23 }, (_, i) => + place({ id: 100 + i, collection_id: 1, name: `Place ${String(i).padStart(2, '0')}` }), + ) + vi.spyOn(collectionsApi, 'get').mockImplementation(async (id: number) => + id === 1 ? detail(listA, many) : detail(listB, []), + ) + setup() + await screen.findByText('Place 00') + + // "Place 22" is well past the first page; the filter has to reach it. + fireEvent.change(screen.getByPlaceholderText(/search/i), { target: { value: 'Place 22' } }) + + expect(screen.getByText('Place 22')).toBeInTheDocument() + expect(screen.queryByText('Place 00')).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: /more/i })).not.toBeInTheDocument() + }) + it('FE-COMP-COLPICKER-001: shows a spinner until the lists have loaded', async () => { const { container } = setup() expect(container.querySelector('.animate-spin')).toBeTruthy() diff --git a/client/src/components/Collections/CollectionPicker.tsx b/client/src/components/Collections/CollectionPicker.tsx index 5cc071c82..f82973b0a 100644 --- a/client/src/components/Collections/CollectionPicker.tsx +++ b/client/src/components/Collections/CollectionPicker.tsx @@ -130,6 +130,11 @@ export default function CollectionPicker({ bias, onSelect, t }: CollectionPicker [bias], ) + // The list is every saved place across every collection, which grows without + // bound. Show a first page and let the rest be asked for. + const PAGE = 10 + const [shown, setShown] = useState(PAGE) + const visible = useMemo(() => { const q = search.trim().toLowerCase() const list = places.filter(p => { @@ -143,6 +148,13 @@ export default function CollectionPicker({ bias, onSelect, t }: CollectionPicker return list }, [places, search, center, listFilter, statusFilter]) + // Searching or filtering starts a new list; keeping the old offset would drop + // the user somewhere in the middle of it. + useEffect(() => { setShown(PAGE) }, [search, listFilter, statusFilter]) + + const page = visible.slice(0, shown) + const remaining = visible.length - page.length + const listOpts: Opt[] = [ { key: 'all', label: t('collections.picker.allLists'), icon: , count: places.length }, ...lists.map(l => ({ @@ -192,7 +204,7 @@ export default function CollectionPicker({ bias, onSelect, t }: CollectionPicker

{t('collections.picker.empty')}

) : (
- {visible.map(place => ( + {page.map(place => ( ))} + {remaining > 0 && ( +
+ +
+ )}
)} diff --git a/client/src/components/Planner/PlaceDetailsColumn.test.tsx b/client/src/components/Planner/PlaceDetailsColumn.test.tsx index 078c4c353..ae9610408 100644 --- a/client/src/components/Planner/PlaceDetailsColumn.test.tsx +++ b/client/src/components/Planner/PlaceDetailsColumn.test.tsx @@ -41,6 +41,7 @@ const GOOGLE_PHOTO = { const RESULT: MapsPlaceEnrichmentResult = { photos: [COMMONS_PHOTO], + facts: [], description: { text: 'Ein Museum in Köln.', source: 'wikipedia', @@ -120,7 +121,7 @@ describe('PlaceDetailsColumn', () => { }) it('FE-PDC-005: names the source when a picture has no author, instead of inventing one', async () => { - placeEnrichment.mockResolvedValue({ photos: [GOOGLE_PHOTO], description: null }) + placeEnrichment.mockResolvedValue({ photos: [GOOGLE_PHOTO], description: null, facts: [] }) renderColumn() expect(await screen.findByText('Google')).toBeInTheDocument() @@ -169,17 +170,69 @@ describe('PlaceDetailsColumn', () => { }) it('FE-PDC-011: says so when the admin switched enrichment off', async () => { - placeEnrichment.mockResolvedValue({ photos: [], description: null, disabled: true }) + placeEnrichment.mockResolvedValue({ photos: [], description: null, facts: [], disabled: true }) renderColumn() expect(await screen.findByText('places.details.disabled')).toBeInTheDocument() }) - it('FE-PDC-012: says so when a place has no pictures', async () => { - placeEnrichment.mockResolvedValue({ photos: [], description: null }) + it('FE-PDC-012: says so when a place yields nothing at all', async () => { + placeEnrichment.mockResolvedValue({ photos: [], description: null, facts: [] }) renderColumn() - expect(await screen.findByText('places.details.noPhotos')).toBeInTheDocument() + expect(await screen.findByText('places.details.nothing')).toBeInTheDocument() + }) + + it('FE-PDC-016: shows the OpenStreetMap facts, which is all a restaurant gets', async () => { + placeEnrichment.mockResolvedValue({ + photos: [], + description: null, + facts: [ + { kind: 'cuisine', value: 'regional', url: null }, + { kind: 'openingHours', value: 'Mo-Sa 17:30+', url: null }, + { kind: 'menu', value: null, url: 'https://example.org/menu' }, + { kind: 'outdoorSeating', value: null, url: null }, + ], + }) + renderColumn() + + // A value is shown verbatim; a plain yes falls back to the translated label. + expect(await screen.findByText('regional')).toBeInTheDocument() + expect(screen.getByText('Mo-Sa 17:30+')).toBeInTheDocument() + expect(screen.getByText('places.details.fact.outdoorSeating')).toBeInTheDocument() + expect(screen.getByRole('link', { name: /places.details.fact.menu/ })).toHaveAttribute( + 'href', + 'https://example.org/menu', + ) + }) + + it('FE-PDC-017: renders facts even when there is neither a picture nor a description', async () => { + placeEnrichment.mockResolvedValue({ + photos: [], + description: null, + facts: [{ kind: 'cuisine', value: 'pizza', url: null }], + }) + renderColumn() + + expect(await screen.findByText('pizza')).toBeInTheDocument() + expect(screen.queryByText('places.details.nothing')).not.toBeInTheDocument() + }) + + it('FE-PDC-018: names Wikivoyage as the source when the text came from there', async () => { + placeEnrichment.mockResolvedValue({ + photos: [], + facts: [], + description: { + text: 'Berlin ist das politische Zentrum Deutschlands.', + source: 'wikivoyage', + sourceUrl: 'https://de.wikivoyage.org/wiki/Berlin', + license: 'CC BY-SA 4.0', + }, + }) + renderColumn() + + const link = await screen.findByRole('link', { name: /Wikivoyage/ }) + expect(link).toHaveAttribute('href', 'https://de.wikivoyage.org/wiki/Berlin') }) it('FE-PDC-013: shows an error state when the request fails', async () => { diff --git a/client/src/components/Planner/PlaceDetailsColumn.tsx b/client/src/components/Planner/PlaceDetailsColumn.tsx index 3e0bbc3bb..c8b8b3f84 100644 --- a/client/src/components/Planner/PlaceDetailsColumn.tsx +++ b/client/src/components/Planner/PlaceDetailsColumn.tsx @@ -1,6 +1,22 @@ import React, { useEffect, useRef, useState } from 'react' -import { Check, ImageOff, Loader2, ExternalLink } from 'lucide-react' -import type { MapsPlaceEnrichmentResult, PlacePhotoCandidate } from '@trek/shared' +import { + Accessibility, + Bike, + Check, + ChefHat, + Clock, + ExternalLink, + ImageOff, + Landmark, + Leaf, + Loader2, + ScrollText, + ShoppingBag, + Sprout, + Sun, + Wifi, +} from 'lucide-react' +import type { MapsPlaceEnrichmentResult, PlaceFact, PlacePhotoCandidate } from '@trek/shared' import { mapsApi } from '../../api/client' import type { TranslationFn } from '../../types' @@ -60,6 +76,16 @@ function cacheKeyFor(selection: PlaceDetailsSelection, language: string): string type LoadState = 'idle' | 'loading' | 'ready' | 'error' +/** + * Overline label, the section heading Vacay and the dashboard widgets share. + * Uppercase with wide tracking, muted, no rule underneath. + */ +function Overline({ children }: { children: React.ReactNode }): React.ReactElement { + return ( +

{children}

+ ) +} + export default function PlaceDetailsColumn({ selection, selectedImageUrl, @@ -127,10 +153,14 @@ export default function PlaceDetailsColumn({ useEffect(() => () => abortRef.current?.abort(), []) + const isEmpty = + state === 'ready' && !data?.disabled && !data?.photos.length && !data?.description && !data?.facts.length + return (