diff --git a/client/src/components/Collections/CollectionPicker.test.tsx b/client/src/components/Collections/CollectionPicker.test.tsx index 335346790..a593c7653 100644 --- a/client/src/components/Collections/CollectionPicker.test.tsx +++ b/client/src/components/Collections/CollectionPicker.test.tsx @@ -329,8 +329,10 @@ describe('CollectionPicker with All places', () => { it('FE-COMP-COLPICKER-022: All places shows the places of the trips beside the lists and hands their facts to the form', async () => { const { props } = setup() await screen.findByText('Zebra Cafe') - expect(placesLibraryRepo.list).not.toHaveBeenCalled() + // Only the count is read up front, with one entry. + await waitFor(() => expect(placesLibraryRepo.list).toHaveBeenCalledWith({ limit: 1 }, expect.any(AbortSignal))) fireEvent.click(screen.getByRole('button', { name: /All lists/ })) + await waitFor(() => expect(within(screen.getByRole('listbox')).getByRole('option', { name: /All places/ })).toHaveTextContent('3')) fireEvent.click(within(screen.getByRole('listbox')).getByRole('option', { name: /All places/ })) await screen.findByText('Old Harbour') diff --git a/client/src/components/Collections/CollectionPicker.tsx b/client/src/components/Collections/CollectionPicker.tsx index 16b7e16d2..79269565b 100644 --- a/client/src/components/Collections/CollectionPicker.tsx +++ b/client/src/components/Collections/CollectionPicker.tsx @@ -4,6 +4,7 @@ import PlaceAvatar from '../shared/PlaceAvatar' import { collectionsApi } from '../../api/collections' import { distinctPlaces, loadUnionPlaces } from '../../store/collectionUnion' import { pickedFromLibrary, usePickerLibrary, type PickerLibraryPlace } from './usePickerLibrary' +import { useLibraryCount } from './useLibraryCount' import { STATUS_META, STATUS_ORDER } from '../../pages/collections/collectionsModel' import type { CollectionPlace, CollectionStatus } from '@trek/shared' import type { TranslationFn } from '../../types' @@ -154,6 +155,8 @@ export default function CollectionPicker({ bias, onSelect, t }: CollectionPicker // 'places' reads All places instead: the trips' places beside the lists'. const [listFilter, setListFilter] = useState('all') const library = usePickerLibrary(listFilter === 'places') + // The count beside All places from the start, before its places are read. + const libraryCount = useLibraryCount(null) const [statusFilter, setStatusFilter] = useState('all') useEffect(() => { @@ -203,7 +206,7 @@ export default function CollectionPicker({ bias, onSelect, t }: CollectionPicker const remaining = visible.length - page.length const listOpts: Opt[] = [ - { key: 'places', label: t('collections.library.title'), icon: , count: library.loaded ? library.places.length : undefined }, + { key: 'places', label: t('collections.library.title'), icon: , count: library.loaded ? library.places.length : libraryCount?.all }, { key: 'all', label: t('collections.picker.allLists'), icon: , count: distinct.length }, ...lists.map(l => ({ key: l.id,