feat(places): All saved shows each place once, All places shows its count

A place saved into several lists from the same trip place showed once per
list in All saved and counted that often, while All places groups the
copies as one place. All saved now shows such a place once, the first
copy read standing for it, and the rail counts All saved and All places
the way All places groups them, on the desktop and the phone.
This commit is contained in:
Maurice
2026-11-30 13:09:01 +01:00
parent b36b83a32e
commit 2204e851fa
11 changed files with 193 additions and 11 deletions
+2 -1
View File
@@ -207,7 +207,8 @@ function CollectionsPageDesktop(): React.ReactElement {
sharedLists={c.sharedLists}
activeId={c.activeId}
libraryActive={c.isLibrary}
savedCount={c.collections.reduce((n, l) => n + (l.place_count ?? 0), 0)}
savedCount={c.libraryCount?.saved ?? c.collections.reduce((n, l) => n + (l.place_count ?? 0), 0)}
libraryCount={c.libraryCount?.all ?? null}
onSelectLibrary={() => c.handleSelectList('library')}
incomingInvites={c.incomingInvites}
onSelect={c.handleSelectList}
+14 -8
View File
@@ -12,9 +12,11 @@ import { downloadCollectionFile, downloadCollectionGpx, downloadCollectionKml, t
import { getApiErrorMessage } from '../../types'
import { PLACES_SAVED, placesPath } from '../../utils/placesRoutes'
import { carryKey, type CopyCarry, type CopyCarryOptions } from '../../components/Collections/useTripCopyPicker'
import { useLibraryCount } from '../../components/Collections/useLibraryCount'
import { canAddToCollection, canRemoveFromCollection, collectionRoleOf } from '../../utils/collectionAccess'
import { addListener, removeListener } from '../../api/websocket'
import { useCollectionStore, ALL_SAVED } from '../../store/collectionStore'
import { distinctPlaces } from '../../store/collectionUnion'
import type { ActiveCollectionId } from '../../store/collectionStore'
import { categoriesApi } from '../../api/client'
import type { Collection, CollectionStatus, CollectionFile } from '@trek/shared'
@@ -97,6 +99,8 @@ export function useCollections() {
// that fails leaves it off, so an offline page never drops the route.
const [listsLoaded, setListsLoaded] = useState(false)
useEffect(() => { loadAll().then(() => setListsLoaded(true), () => setListsLoaded(false)) }, [])
// All places and All saved in the rail, each place once; read again when a list changes.
const libraryCount = useLibraryCount(collections)
// Central admin-defined categories, for assigning a category to a saved place.
const [categories, setCategories] = useState<Category[]>([])
@@ -223,6 +227,8 @@ export function useCollections() {
[collections, activeId],
)
const isAllSaved = activeId === ALL_SAVED
// All saved shows a place kept in several lists once; a single list shows its own.
const shownPlaces = useMemo(() => (isAllSaved ? distinctPlaces(places) : places), [isAllSaved, places])
const isOwner = activeCollection?.is_owner ?? false
// The current user's permission on the active list drives what the UI offers.
@@ -255,8 +261,8 @@ export function useCollections() {
// Labels are per-collection, so never apply them on the "All saved" union.
const visiblePlaces = useMemo(
() => sortPlaces(filterPlaces(places, statusFilter, search, categoryFilter, isAllSaved ? [] : labelFilter, ratingFilter), sortMode),
[places, statusFilter, search, categoryFilter, isAllSaved, labelFilter, ratingFilter, sortMode],
() => sortPlaces(filterPlaces(shownPlaces, statusFilter, search, categoryFilter, isAllSaved ? [] : labelFilter, ratingFilter), sortMode),
[shownPlaces, statusFilter, search, categoryFilter, isAllSaved, labelFilter, ratingFilter, sortMode],
)
// The list's own order can be dragged (#1457) only while every place of it is on
// screen in that order: a single list, its own sort, no search or filter hiding
@@ -269,9 +275,9 @@ export function useCollections() {
reorderPlaces(orderedIds).catch((err: unknown) => toast.error(getApiErrorMessage(err, t('common.error'))))
}, [reorderPlaces, toast, t])
// Categories actually present in this list, for the category filter dropdown.
const categoryOptions = useMemo(() => presentCategories(places), [places])
const categoryOptions = useMemo(() => presentCategories(shownPlaces), [shownPlaces])
// The active list's labels (with per-label counts) for the filter + manager.
const labelOptions = useMemo(() => presentLabels(labels, places), [labels, places])
const labelOptions = useMemo(() => presentLabels(labels, shownPlaces), [labels, shownPlaces])
// Stable reference so the map doesn't tear down + rebuild every marker on each
// unrelated re-render (which would swallow marker clicks mid-rebuild).
const mappable = useMemo(() => mappablePlaces(visiblePlaces), [visiblePlaces])
@@ -279,8 +285,8 @@ export function useCollections() {
// hangs off this rather than off `mappable`: a label with no places left the
// filtered set empty, which tore the map out and reflowed the page to full
// width. The filter should empty the map, not remove it.
const hasMappable = useMemo(() => mappablePlaces(places).length > 0, [places])
const counts = useMemo(() => statusCounts(places), [places])
const hasMappable = useMemo(() => mappablePlaces(shownPlaces).length > 0, [shownPlaces])
const counts = useMemo(() => statusCounts(shownPlaces), [shownPlaces])
// ── Handlers ────────────────────────────────────────────────────────
const handleSelectList = useCallback((id: ActiveCollectionId | 'library') => {
@@ -591,11 +597,11 @@ export function useCollections() {
listColRef: listCol.ref, listColRect: listCol.rect, mapColRef: mapCol.ref, mapColRect: mapCol.rect, categories,
mapLocked, toggleMapLocked,
// store data
collections, ownedLists, sharedLists, activeCollection, isAllSaved, isOwner,
collections, ownedLists, sharedLists, activeCollection, isAllSaved, isOwner, libraryCount,
copyCarryOptions,
myRole, canEdit, canDelete, reorderEnabled, reorderBlocked, commitOrder,
canShare, shareMemberCount,
activeId, places, visiblePlaces, mappable, hasMappable, members, incomingInvites, routeInvite, orderedInvites, counts,
activeId, places: shownPlaces, visiblePlaces, mappable, hasMappable, members, incomingInvites, routeInvite, orderedInvites, counts,
view, statusFilter, categoryFilter, categoryOptions, ratingFilter, sortMode, search, selectedPlaceId, selectMode, selectedIds,
labels, labelFilter, labelOptions,
loading, placesLoading,