feat(places): the picker shows how many places All places holds from the start

The count beside All places in the place dialog's picker appeared only
once All places was chosen and read. It is now read with the picker,
with one entry, the way the rail reads it.
This commit is contained in:
Maurice
2026-11-30 13:10:34 +01:00
parent 91bf941e4c
commit 51c45d0573
2 changed files with 7 additions and 2 deletions
@@ -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')
@@ -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<number | 'all' | 'places'>('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<CollectionStatus | 'all'>('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: <Globe2 size={13} />, count: library.loaded ? library.places.length : undefined },
{ key: 'places', label: t('collections.library.title'), icon: <Globe2 size={13} />, count: library.loaded ? library.places.length : libraryCount?.all },
{ key: 'all', label: t('collections.picker.allLists'), icon: <Layers size={13} />, count: distinct.length },
...lists.map(l => ({
key: l.id,