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:
{t('collections.picker.empty')}
) : ({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 (