Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

merge: update Tours branch with current Places filters

elmocito2ec5ae7e4d5e
diff --cc client/src/components/Planner/usePlacesSidebar.test.tsx
index 4e22159f4,07aaf764b..68078f0a5
--- a/client/src/components/Planner/usePlacesSidebar.test.tsx
+++ b/client/src/components/Planner/usePlacesSidebar.test.tsx
@@@ -188,13 -188,10 +188,46 @@@ describe('usePlacesSidebar filtering',
expect(names()).toEqual(['GPX Track']);
});
- it('FE-PLANNER-PSHOOK-008: a tracks filter without any track falls back to "all"', async () => {
- seedStore(useTripStore, { placesFilter: 'tracks' });
- render(<Host {...makeProps({ places: [buildPlace({ name: 'Plain Spot' })] })} />);
- await waitFor(() => expect(useTripStore.getState().placesFilter).toBe('all'));
- expect(names()).toEqual(['Plain Spot']);
++ it('Tours addon excludes Tour-backed Places from rows, counts, and localities', () => {
++ const legacyTrack = buildPlace({ id: 41, name: 'Legacy track', route_geometry: '[[1,2],[3,4]]', rating_avg: 4, address: 'Vienna, Austria' });
++ const ordinary = buildPlace({ id: 42, name: 'Ordinary place', address: 'Linz, Austria' });
++ const tour = buildPlace({ id: 43, name: 'Tour place', tour_place_id: 43, route_geometry: '[[5,6],[7,8]]', address: 'Denver, United States' });
++ render(<Host {...makeProps({
++ places: [legacyTrack, ordinary, tour],
++ toursEnabled: true,
++ excludePlaceIds: new Set([tour.id]),
++ })} />);
++
++ expect(S.hasTracks).toBe(false);
++ expect(names()).toEqual(expect.arrayContaining(['Legacy track', 'Ordinary place']));
++ expect(names()).not.toContain('Tour place');
++ expect(S.filterCounts).toEqual({ all: 2, unplanned: 2, planned: 0, tracks: 1 });
++ expect(S.localities).toEqual([{ country: 'Austria', count: 2, regions: [] }]);
++
++ act(() => { S.setRatingFilter(4); });
++ expect(names()).toEqual(['Legacy track']);
++ expect(S.filterCounts.all).toBe(2);
+ });
+
++ it('Tours addon OFF preserves legacy track Places and ignores the exclusion set', () => {
++ const legacyTrack = buildPlace({ id: 51, name: 'Legacy track', route_geometry: '[[1,2],[3,4]]' });
++ const dormantTour = buildPlace({ id: 52, name: 'Dormant Tour', tour_place_id: 52, route_geometry: '[[5,6],[7,8]]' });
++ render(<Host {...makeProps({
++ places: [legacyTrack, dormantTour],
++ toursEnabled: false,
++ excludePlaceIds: new Set([dormantTour.id]),
++ })} />);
++
++ expect(S.hasTracks).toBe(true);
++ expect(S.filterCounts).toEqual({ all: 2, unplanned: 2, planned: 0, tracks: 2 });
++ act(() => { S.setFilter('tracks'); });
++ expect(names()).toEqual(expect.arrayContaining(['Legacy track', 'Dormant Tour']));
++ });
++
+ // FE-PLANNER-PSHOOK-008 (a tracks filter without any track falls back to "all")
+ // moved to useTripPlanner (FE-TP-HOOK-177): the fallback now lives there, so it
+ // also holds while no places list is mounted.
+
it('FE-PLANNER-PSHOOK-009: a category filter keeps only that category', () => {
const tagged = buildPlace({ name: 'Tagged', category_id: 4 });
const other = buildPlace({ name: 'Other', category_id: 5 });
diff --cc client/src/components/Planner/usePlacesSidebar.ts
index 96d196385,6a6c9abf5..4ca56c0fd
--- a/client/src/components/Planner/usePlacesSidebar.ts
+++ b/client/src/components/Planner/usePlacesSidebar.ts
@@@ -205,8 -196,8 +207,8 @@@ export function usePlacesSidebar(props
// Country, or country and region, from each place's resolved position (#2537). List-only,
// like the rating floor.
const [localityFilter, setLocalityFilter] = useState<LocalityFilter | null>(null)
-- const localityOf = useMemo(() => new Map(places.map(p => [p.id, placeLocality(p, language)])), [places, language])
- const localities = useMemo(() => localityGroups(places.map(p => localityOf.get(p.id)!)), [places, localityOf])
++ const localityOf = useMemo(() => new Map(poolPlaces.map(p => [p.id, placeLocality(p, language)])), [poolPlaces, language])
+ const localities = useMemo(() => localityGroups(poolPlaces.map(p => localityOf.get(p.id)!)), [poolPlaces, localityOf])
const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set())
const [pendingDeleteIds, setPendingDeleteIds] = useState<number[] | null>(null)
const [categoryPickerOpen, setCategoryPickerOpen] = useState(false)
@@@ -268,11 -259,9 +270,10 @@@
const pickFilter = (next: PlacesFilter) => { setFilter(next); setSelectedIds(new Set()) }
// Alle geplanten Ort-IDs abrufen (einem Tag zugewiesen)
- // Whether to offer the "Tracks" tab. useTripPlanner moves the filter back to
- // "all" once the last track is gone, whichever screen is in front.
- const hasTracks = useMemo(() => places.some(p => p.route_geometry), [places])
+ const hasTracks = useMemo(
+ () => !props.toursEnabled && poolPlaces.some(p => p.route_geometry),
+ [poolPlaces, props.toursEnabled],
+ )
- useEffect(() => { if (filter === 'tracks' && !hasTracks) setFilter('all') }, [hasTracks, filter])
const plannedIds = useMemo(
() => plannedPlaceIds({ assignments, accommodations, reservations }),
@@@ -300,17 -289,9 +301,9 @@@
const dayScoped = filter === 'planned' && plannedInDayIds !== null
const filtered = useMemo(() => {
- const list = places.filter(p => {
+ const list = poolPlaces.filter(p => {
- if (filter === 'unplanned' && plannedIds.has(p.id)) return false
- if (filter === 'planned' && !plannedFilterIds.has(p.id)) return false
- if (filter === 'tracks' && !p.route_geometry) return false
- if (categoryFilters.size > 0) {
- if (p.category_id == null) {
- if (!categoryFilters.has('uncategorized')) return false
- } else if (!categoryFilters.has(String(p.category_id))) return false
- }
+ if (!matchesPlacesFilter(p, { filter, categoryFilters, ratingFilter }, { plannedIds, plannedFilterIds })) return false
if (!placeMatchesSearch(p, search)) return false
- if (ratingFilter !== 'all' && (p.rating_avg == null || p.rating_avg < ratingFilter)) return false
if (localityFilter && !matchesLocality(localityOf.get(p.id), localityFilter)) return false
return true
})
@@@ -325,14 -306,7 +318,7 @@@
* different questions.
*/
const filterCounts = useMemo(() => {
- const base = poolPlaces.filter(p => {
- if (categoryFilters.size > 0) {
- if (p.category_id == null) {
- if (!categoryFilters.has('uncategorized')) return false
- } else if (!categoryFilters.has(String(p.category_id))) return false
- }
- return placeMatchesSearch(p, search)
- })
- const base = places.filter(p => matchesCategoryFilter(p, categoryFilters) && placeMatchesSearch(p, search))
++ const base = poolPlaces.filter(p => matchesCategoryFilter(p, categoryFilters) && placeMatchesSearch(p, search))
return {
all: base.length,
unplanned: base.filter(p => !plannedIds.has(p.id)).length,
diff --cc client/src/mobile/screens/trip/places/MPlacesBrowser.tsx
index d69e8f9d6,19da6cdc4..2b9a5b2f4
--- a/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx
+++ b/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx
@@@ -21,10 -21,9 +21,12 @@@ import { useTranslation } from '../../.
import type { Place } from '../../../../types'
import MPlacesBulkCategorySheet from './MPlacesBulkCategorySheet'
import MPlacesSaveToCollectionSheet from './MPlacesSaveToCollectionSheet'
+import MPlacesToursModeSwitch from './MPlacesToursModeSwitch'
+import MToursSelectionList from './MToursSelectionList'
import { filterPool, firstPlannedDayNumbers, plannedPlaceIds } from './placesBrowserModel'
+import { useTourPlaceIds } from '../../../../hooks/useTourPlaceIds'
+ import { MCategoryFilterList, MRatingFloorChips, SquareCheck } from './MPlacesFilterControls'
+ import { countActivePlacesFilters } from '../../../../utils/placesFilter'
/**
* Fullscreen places pool (mode === 'browse'): All/Unplanned/Tracks filter
@@@ -72,10 -64,9 +74,7 @@@ export default function MPlacesBrowser(
if (shell.browseFromEdit) setFilter('unplanned')
}, [shell.browseFromEdit, setFilter])
- // Whether to offer the "Tracks" chip; useTripPlanner moves the filter back to
- // "all" once the last track is gone.
- const hasTracks = useMemo(() => places.some(p => p.route_geometry), [places])
+ const hasTracks = useMemo(() => !toursEnabled && places.some(p => p.route_geometry), [places, toursEnabled])
- useEffect(() => {
- if (filter === 'tracks' && !hasTracks) setFilter('all')
- }, [filter, hasTracks, setFilter])
// A hotel is linked through its stay and a venue through its booking; neither is
// ever dragged onto a day, and the pool used to call both unplanned (#2072).
@@@ -84,10 -75,10 +83,13 @@@
[assignments, planner.tripAccommodations, planner.reservations],
)
const dayNumberByPlace = useMemo(() => firstPlannedDayNumbers(assignments, days), [assignments, days])
- const filtered = useMemo(
- () => filterPool(places, { filter, categoryFilters, ratingFilter, search, plannedIds }),
- [places, filter, categoryFilters, ratingFilter, search, plannedIds],
++ const poolPlaces = useMemo(
++ () => toursEnabled ? places.filter(place => !tourPlaceIds.has(place.id)) : places,
++ [places, toursEnabled, tourPlaceIds],
+ )
+ const filtered = useMemo(() => {
- const pool = toursEnabled ? places.filter(p => !tourPlaceIds.has(p.id)) : places
- return filterPool(pool, { filter, categoryFilters, search, plannedIds })
- }, [places, filter, categoryFilters, search, plannedIds, toursEnabled, tourPlaceIds])
++ return filterPool(poolPlaces, { filter, categoryFilters, ratingFilter, search, plannedIds })
++ }, [poolPlaces, filter, categoryFilters, ratingFilter, search, plannedIds])
// A bulk delete (or a remote edit) can remove selected places — drop the
// stale ids so the toolbar count stays honest.
@@@ -131,20 -122,12 +133,13 @@@
// Compare the ids, not just the counts: a place removed remotely while another
// one is selected keeps the sizes equal without the sets matching.
- const allSelected = filtered.length > 0 && filtered.every(p => selectedIds.has(p.id))
+ const selectablePlaces = filtered.filter(place => !planner.isTourPlace(place.id))
+ const allSelected = selectablePlaces.length > 0 && selectablePlaces.every(p => selectedIds.has(p.id))
const toggleAllVisible = () => {
if (allSelected) setSelectedIds(new Set())
- else setSelectedIds(new Set(filtered.map(p => p.id)))
+ else setSelectedIds(new Set(selectablePlaces.map(p => p.id)))
}
- const toggleCategory = (catId: string) => {
- const next = new Set(categoryFilters)
- if (next.has(catId)) next.delete(catId)
- else next.add(catId)
- setCategoryFilters(next)
- }
-
const openAddPlace = () => {
planner.setEditingPlace(null)
planner.setEditingAssignmentId(null)
@@@ -164,29 -143,14 +159,28 @@@
shell.openSheet('bract', { placeId: place.id, dayPicker: false })
}
- // The panel holds the categories and the rating floor; its badge counts them the
- // way the map's Filters badge does (one per kind of filter). The pool is left out:
- // its chips sit in plain sight above the panel.
+ const selectedTours = [...selectedIds].filter(planner.isTourPlace)
-
- const hasUncategorized = places.some(p => p.category_id == null)
+ const panelFilterCount = countActivePlacesFilters({ filter: 'all', categoryFilters, ratingFilter })
return (
<div className="flex h-full flex-col">
- <div className="min-h-0 flex-1 overflow-y-auto px-4 pb-[calc(var(--bottom-nav-h,84px)+22px)] pt-[calc(var(--m-safe-top,12px)+58px)]">
+ <div className="min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-4 pb-[calc(var(--bottom-nav-h,84px)+22px)] pt-[calc(var(--m-safe-top,12px)+58px)]">
+ {toursEnabled && (
+ <MPlacesToursModeSwitch active={toursMode} onChange={setToursMode} />
+ )}
+ {toursEnabled && toursMode ? (
+ <>
+ {/* All / Unplanned / Planned only — no Tracks chip, no Import/Add/Select
+ buttons: tours are attached here, never created or bulk-managed. */}
+ <div className="flex items-center gap-[6px]">
+ <FilterChip active={toursFilter === 'all'} label={t('places.all')} onClick={() => setToursFilter('all')} />
+ <FilterChip active={toursFilter === 'unplanned'} label={t('places.unplanned')} onClick={() => setToursFilter('unplanned')} />
+ <FilterChip active={toursFilter === 'planned'} label={t('places.planned')} onClick={() => setToursFilter('planned')} />
+ </div>
+ <MToursSelectionList planner={planner} shell={shell} filter={toursFilter} />
+ </>
+ ) : (
+ <>
{/* ── Filter chips + Import (Add sits in the search row below to free space) ── */}
<div className="flex items-center gap-[6px]">
<FilterChip
@@@ -324,31 -288,13 +318,13 @@@
</div>
)}
- {/* ── Category filter panel ── */}
+ {/* ── Rating + category filter panel ── */}
{catOpen && (
<div className="mt-[6px] overflow-hidden rounded-2xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-glass)]">
- {categories.map(c => {
- const CatIcon = getCategoryIcon(c.icon)
- return (
- <CategoryFilterRow
- key={c.id}
- checked={categoryFilters.has(String(c.id))}
- onToggle={() => toggleCategory(String(c.id))}
- label={c.name}
- >
- <CatIcon size={14} strokeWidth={2} className="flex-none" style={{ color: c.color || 'var(--m-muted)' }} />
- </CategoryFilterRow>
- )
- })}
- {hasUncategorized && (
- <CategoryFilterRow
- checked={categoryFilters.has('uncategorized')}
- onToggle={() => toggleCategory('uncategorized')}
- label={t('places.noCategory')}
- >
- <MapPin size={14} strokeWidth={2} className="flex-none text-m-faint" />
- </CategoryFilterRow>
- )}
+ <div className="border-b border-[color:var(--m-rowbr)] px-[13px] py-[10px]">
+ <MRatingFloorChips onPick={() => setSelectedIds(new Set())} />
+ </div>
- <MCategoryFilterList categories={categories} places={places} />
++ <MCategoryFilterList categories={categories} places={poolPlaces} />
</div>
)}
diff --cc client/src/mobile/screens/trip/places/MPlacesFilterSheet.tsx
index 000000000,cea5633fd..51a80744b
mode 000000,100644..100644
--- a/client/src/mobile/screens/trip/places/MPlacesFilterSheet.tsx
+++ b/client/src/mobile/screens/trip/places/MPlacesFilterSheet.tsx
@@@ -1,0 -1,99 +1,100 @@@
+ import { RotateCcw, X } from 'lucide-react'
+ import MSheet from '../../../components/MSheet'
+ import MIconBtn from '../../../components/MIconBtn'
+ import MChip from '../../../components/MChip'
+ import { useTripStore } from '../../../../store/tripStore'
+ import { countActivePlacesFilters } from '../../../../utils/placesFilter'
+ import { useTranslation } from '../../../../i18n'
+ import type { Category, Place } from '../../../../types'
+ import { MCategoryFilterList, MRatingFloorChips } from './MPlacesFilterControls'
+
+ interface MPlacesFilterSheetProps {
+ open: boolean
+ onClose: () => void
+ places: Place[]
+ categories: Category[]
++ toursEnabled: boolean
+ }
+
+ /** Uppercase eyebrow over each group of the sheet. */
+ function SectionTitle({ children }: { children: string }) {
+ return (
+ <div className="mb-2 font-geist text-[0.625rem] font-bold uppercase tracking-[.09em] text-m-faint">{children}</div>
+ )
+ }
+
+ /**
+ * The places filter, opened from the phone map: which pool to show, a minimum
+ * rating and the trip's categories, with one button that lifts them all. Every
+ * choice lands in the trip store at once, so the markers behind the sheet and the
+ * places list change with it (#1541). Routed as shell sheet 'placesFilter'.
+ */
-export default function MPlacesFilterSheet({ open, onClose, places, categories }: MPlacesFilterSheetProps) {
++export default function MPlacesFilterSheet({ open, onClose, places, categories, toursEnabled }: MPlacesFilterSheetProps) {
+ const { t } = useTranslation()
+ const filter = useTripStore(s => s.placesFilter)
+ const categoryFilters = useTripStore(s => s.placesCategoryFilter)
+ const ratingFilter = useTripStore(s => s.placesRatingFilter)
+ const setFilter = useTripStore(s => s.setPlacesFilter)
+ const resetPlacesFilters = useTripStore(s => s.resetPlacesFilters)
+ const activeCount = countActivePlacesFilters({ filter, categoryFilters, ratingFilter })
+
+ const pools = [
+ { id: 'all', label: t('places.all') },
+ { id: 'unplanned', label: t('places.unplanned') },
+ { id: 'planned', label: t('places.planned') },
+ ]
- if (places.some(p => p.route_geometry)) pools.push({ id: 'tracks', label: t('places.filterTracks') })
++ if (!toursEnabled && places.some(p => p.route_geometry)) pools.push({ id: 'tracks', label: t('places.filterTracks') })
+ const hasCategoryChoice = categories.length > 0 || places.some(p => p.category_id == null)
+
+ return (
+ // Opaque: the sheet opens over the map, and the default bar glass let the map's
+ // place names show through the chips and category rows (seen at 390px wide).
+ <MSheet open={open} onClose={onClose} variant="bottom" material="opaque" ariaLabel={t('places.filters')}>
+ <div className="flex flex-none items-center border-b border-[color:var(--m-rowbr)] px-[18px] pb-[11px] pt-4">
+ <div className="min-w-0 flex-1 text-[1.03125rem] font-bold text-m-ink">{t('places.filters')}</div>
+ <MIconBtn variant="neutral" size={34} onClick={onClose} ariaLabel={t('common.close')}>
+ <X size={15} strokeWidth={2.2} />
+ </MIconBtn>
+ </div>
+
+ <div className="min-h-0 flex-1 overflow-y-auto px-[18px] pb-3 pt-[14px]">
+ <section>
+ <SectionTitle>{t('places.filterShow')}</SectionTitle>
+ <div role="group" aria-label={t('places.filterShow')} className="flex flex-wrap gap-[6px]">
+ {pools.map(pool => (
+ <MChip key={pool.id} size="tap" pressable active={filter === pool.id} onClick={() => setFilter(pool.id)}>
+ {pool.label}
+ </MChip>
+ ))}
+ </div>
+ </section>
+
+ <section className="mt-[18px]">
+ <SectionTitle>{t('places.filterByRating')}</SectionTitle>
+ <MRatingFloorChips />
+ </section>
+
+ {hasCategoryChoice && (
+ <section className="mt-[18px]">
+ <SectionTitle>{t('categories.title')}</SectionTitle>
+ <div className="overflow-hidden rounded-2xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)]">
+ <MCategoryFilterList categories={categories} places={places} />
+ </div>
+ </section>
+ )}
+ </div>
+
+ <div className="flex flex-none border-t border-[color:var(--m-rowbr)] px-[18px] py-3">
+ <button
+ type="button"
+ onClick={resetPlacesFilters}
+ disabled={activeCount === 0}
+ className="flex min-h-[44px] flex-1 items-center justify-center gap-2 rounded-full border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] text-[0.8125rem] font-semibold text-m-ink disabled:opacity-40"
+ >
+ <RotateCcw size={14} strokeWidth={2.2} />
+ {t('common.reset')}
+ </button>
+ </div>
+ </MSheet>
+ )
+ }
diff --cc client/src/mobile/screens/trip/plan/MPlanTimeline.tsx
index 0fc365be6,84f921cd3..f4731ee19
--- a/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx
+++ b/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx
@@@ -160,14 -160,9 +160,14 @@@ export default function MPlanTimeline(
<div
ref={cardRef}
data-touch-drag={editing ? '' : undefined}
- className="absolute left-4 right-4 overflow-y-auto overscroll-contain rounded-[22px] border border-[color:var(--m-cbr)] bg-[color:var(--m-card)] px-3.5 pb-2 pt-1 backdrop-blur-[24px] backdrop-saturate-[1.6] bottom-[calc(env(safe-area-inset-bottom,0px)+90px)]"
+ className="absolute left-4 right-4 overflow-x-hidden overflow-y-auto overscroll-contain rounded-[22px] border border-[color:var(--m-cbr)] bg-[color:var(--m-card)] px-3.5 pb-2 pt-1 backdrop-blur-[24px] backdrop-saturate-[1.6] bottom-[calc(env(safe-area-inset-bottom,0px)+90px)]"
style={{ top: `calc(var(--m-safe-top, 12px) + ${editing ? 140 : tl.upNext ? 216 : 102}px)` }}
>
+ {planner.toursEnabled && tl.rows.some(row => row.kind === 'place' && row.invalidTour) && (
+ <div role="status" className="border-b border-[color:var(--warning)] p-2 text-sm text-[color:var(--warning)]">
+ {t('tours.dayRoute.endpointUnknown')}
+ </div>
+ )}
{day && (
<TimelineHeader
tl={tl}
diff --cc client/src/mobile/screens/trip/sheets/MTripSheets.tsx
index 329edaba2,3b3aca377..5b9fcb8e2
--- a/client/src/mobile/screens/trip/sheets/MTripSheets.tsx
+++ b/client/src/mobile/screens/trip/sheets/MTripSheets.tsx
@@@ -150,6 -92,12 +151,13 @@@ export default function MTripSheets({ p
onClose={shell.closeSheet}
/>
<MImportSheet planner={planner} open={sheet?.id === 'import'} onClose={shell.closeSheet} />
+ <MPlacesFilterSheet
+ open={sheet?.id === 'placesFilter'}
+ onClose={shell.closeSheet}
+ places={planner.places}
+ categories={planner.categories}
++ toursEnabled={planner.toursEnabled}
+ />
{/* ── Planner-flag editors (also serve ?create= and the import review) ── */}
<MPlaceEditSheet planner={planner} onOpenExpense={openBookingExpense} />
diff --cc client/src/pages/tripPlanner/useTripPlanner.test.tsx
index 547bc4197,33cf5c255..a8a4854e6
--- a/client/src/pages/tripPlanner/useTripPlanner.test.tsx
+++ b/client/src/pages/tripPlanner/useTripPlanner.test.tsx
@@@ -646,6 -644,23 +646,47 @@@ describe('useTripPlanner — map deriva
expect(result.current.mapPlaces.map(p => p.id)).toEqual([2])
})
+ it('FE-TP-HOOK-177: losing the last track moves the "Tracks" filter back to all', async () => {
+ // The phone map has no places list mounted, so this hook is what keeps the
+ // filter from pointing at a pool no control offers any more.
+ seedTrip({
+ places: [geo(1), geo(2, { route_geometry: '[[1,2]]' })],
+ placesFilter: 'tracks',
+ })
+
+ const { result } = await renderPlanner()
+ expect(useTripStore.getState().placesFilter).toBe('tracks')
+
+ act(() => { useTripStore.setState({ places: [geo(1)] }) })
+
+ await waitFor(() => expect(useTripStore.getState().placesFilter).toBe('all'))
+ expect(result.current.mapPlaces.map(p => p.id)).toEqual([1])
+ })
+
++ it('Tours enabled clears a stale Tracks filter even while track geometry remains', async () => {
++ const tour: TourListItem = {
++ place_id: 7, name: 'Ridge walk', tour_type: 'hike', distance: 4, elevation_gain: 100,
++ elevation_loss: 80, duration: null, difficulty: null, wanderer_ref: null, match_confidence: 1,
++ tour_group_id: null, max_hiking_difficulty: 2, planned: false, caution: false,
++ }
++ useAddonStore.setState({ addons: [{ id: 'tours', enabled: true } as never], loaded: true })
++ vi.mocked(addonsApi.enabled).mockResolvedValue({ addons: [{ id: 'tours' }] })
++ vi.spyOn(toursApi, 'list').mockResolvedValue({ tours: [tour] })
++ seedTrip({
++ places: [
++ buildPlace({ id: 7, lat: 1, lng: 2, tour_place_id: 7, route_geometry: '[[1,2],[3,4]]' }),
++ buildPlace({ id: 8, lat: 3, lng: 4, route_geometry: '[[5,6],[7,8]]' }),
++ ],
++ placesFilter: 'tracks',
++ })
++
++ const { result } = await renderPlanner()
++ await waitFor(() => expect(useTripStore.getState().placesFilter).toBe('all'))
++
++ expect(result.current.enabledAddons.tours).toBe(true)
++ expect(result.current.mapPlaces.map(place => place.id)).toEqual([7, 8])
++ })
++
it('FE-TP-HOOK-027: the category filter honours the uncategorized bucket', async () => {
seedTrip({
places: [geo(1, { category_id: 3 }), geo(2, { category_id: null })],
diff --cc client/src/pages/tripPlanner/useTripPlanner.ts
index 387476dd1,25b85e4c4..993ee1055
--- a/client/src/pages/tripPlanner/useTripPlanner.ts
+++ b/client/src/pages/tripPlanner/useTripPlanner.ts
@@@ -792,7 -766,18 +788,18 @@@ export function useTripPlanner()
const pending = pendingIds.has(p.id)
return compact || pending ? { ...p, _compact: compact, _pending: pending } : p
})
- }, [places, placesCategoryFilter, placesFilter, assignments, expandedDayIds, selectedDayId, days, tripAccommodations, reservations, compactUnplanned])
+ }, [places, placesCategoryFilter, placesFilter, placesRatingFilter, assignments, expandedDayIds, selectedDayId, days, tripAccommodations, reservations, compactUnplanned])
+
+ // The "Tracks" pool is only offered while a place carries a track. When the last
+ // one goes (deleted here or by a collaborator), fall back to "all" — here, because
+ // this hook is mounted whatever is on screen: the lists that used to do it are not
+ // mounted while the phone map is in front, and the map would sit empty under a
+ // "Tracks" filter no control offers any more.
+ const setPlacesFilter = useTripStore((s) => s.setPlacesFilter)
- const hasTracks = useMemo(() => places.some(p => p.route_geometry), [places])
++ const hasTracks = useMemo(() => !toursEnabled && places.some(p => p.route_geometry), [places, toursEnabled])
+ useEffect(() => {
+ if (placesFilter === 'tracks' && !hasTracks) setPlacesFilter('all')
+ }, [placesFilter, hasTracks, setPlacesFilter])
const { route, routeWalking, routeSegments, routeVias, routeInfo, setRoute, setRouteInfo, updateRouteForDay } = useRouteCalculation({ assignments } as any, selectedDayId, routeShown, routeProfile, tripAccommodations)
// Road trip mode already draws the whole trip its own way, so the overview stands
diff --cc client/tests/unit/mobile/trip/MPlacesBrowser.test.tsx
index c1b47e909,d13024ada..5ddad84d0
--- a/client/tests/unit/mobile/trip/MPlacesBrowser.test.tsx
+++ b/client/tests/unit/mobile/trip/MPlacesBrowser.test.tsx
@@@ -3,7 -3,7 +3,8 @@@ import { act, fireEvent, render, screen
import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'
import MPlacesBrowser from '../../../../src/mobile/screens/trip/places/MPlacesBrowser'
import { collectionsApi } from '../../../../src/api/collections'
--import type { CollectionListResponse } from '@trek/shared'
++import { toursApi } from '../../../../src/api/client'
++import type { CollectionListResponse, TourListItem } from '@trek/shared'
import { useAddonStore } from '../../../../src/store/addonStore'
import { useTripStore } from '../../../../src/store/tripStore'
import { resetAllStores, seedStore } from '../../../helpers/store'
@@@ -291,23 -343,6 +345,51 @@@ describe('MPlacesBrowser', () =>
expect(screen.queryByText(/places.selectionCount/)).not.toBeInTheDocument()
})
+ it('routes a Tour row to read-only detail instead of mobile Place bulk management', () => {
+ const planner = makePlanner({
+ places: [LOUVRE, TOUR],
+ isTourPlace: vi.fn((placeId: number) => placeId === TOUR.id),
+ })
+ renderBrowser(planner)
+ fireEvent.click(screen.getByRole('button', { name: 'common.select' }))
+ fireEvent.click(row('Louvre'))
+ fireEvent.click(row('Ridge walk'))
+
+ expect(planner.handlePlaceClick).toHaveBeenCalledWith(TOUR.id)
+ expect(screen.getByText('places.selectionCount:1')).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'places.deleteSelected' })).toBeEnabled()
+ expect(screen.getByRole('button', { name: 'places.changeCategory' })).toBeEnabled()
+ expect(screen.getByRole('button', { name: 'common.deselectAll' })).toBeInTheDocument()
+ })
+
++ it('keeps Tour-backed Places out of the Places pool and Tours mode browse/attach only', async () => {
++ const ridge: TourListItem = {
++ place_id: TOUR.id, name: 'Ridge walk', tour_type: 'hike', distance: 4, elevation_gain: 100,
++ elevation_loss: 80, duration: null, difficulty: null, wanderer_ref: null, match_confidence: 1,
++ tour_group_id: null, max_hiking_difficulty: 2, planned: false, caution: false,
++ }
++ seedStore(useAddonStore, { addons: [{ id: 'collections', enabled: true }, { id: 'tours', enabled: true }] })
++ vi.spyOn(toursApi, 'list').mockResolvedValue({ tours: [ridge] })
++ const planner = makePlanner({
++ places: [...PLACES, TOUR],
++ tours: [ridge],
++ isTourPlace: vi.fn((placeId: number) => placeId === TOUR.id),
++ })
++ const { shell } = renderBrowser(planner)
++
++ await waitFor(() => expect(screen.getByText('places.count:3')).toBeInTheDocument())
++ expect(screen.queryByText('Ridge walk')).not.toBeInTheDocument()
++ expect(toursApi.list).toHaveBeenCalledWith(planner.tripId)
++
++ fireEvent.click(screen.getByRole('tab', { name: /^Tours$/i }))
++ expect(screen.getByRole('option', { name: /Ridge walk/ })).toBeInTheDocument()
++ expect(screen.queryByText('Louvre')).not.toBeInTheDocument()
++ expect(screen.queryByRole('button', { name: 'mobileTrip.importPlaces' })).not.toBeInTheDocument()
++ expect(screen.queryByRole('button', { name: 'common.add' })).not.toBeInTheDocument()
++ expect(screen.queryByRole('button', { name: 'common.select' })).not.toBeInTheDocument()
++ expect(screen.getByRole('button', { name: /tours.addToDay|Add to day/i })).toBeInTheDocument()
++ })
++
it('FE-MOB-PBROW-020b: a failed bulk delete keeps the selection for a retry', async () => {
const planner = makePlanner()
;(planner.confirmDeletePlaces as ReturnType<typeof vi.fn>).mockRejectedValueOnce(new Error('nope'))
diff --cc client/tests/unit/mobile/trip/MPlacesFilterSheet.test.tsx
index 000000000,e6c71fdd7..cc237db43
mode 000000,100644..100644
--- a/client/tests/unit/mobile/trip/MPlacesFilterSheet.test.tsx
+++ b/client/tests/unit/mobile/trip/MPlacesFilterSheet.test.tsx
@@@ -1,0 -1,120 +1,128 @@@
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
+ import { fireEvent, render, screen, within } from '../../../helpers/render'
+ import MPlacesFilterSheet from '../../../../src/mobile/screens/trip/places/MPlacesFilterSheet'
+ import { useTripStore } from '../../../../src/store/tripStore'
+ import { resetAllStores, seedStore } from '../../../helpers/store'
+ import { buildPlace } from '../../../helpers/factories'
+ import type { Category, Place } from '../../../../src/types'
+
+ // FE-MOB-PFSHEET-001 to FE-MOB-PFSHEET-009
+
+ const CATEGORIES = [
+ { id: 1, name: 'Sights', color: '#123456', icon: 'landmark' },
+ { id: 2, name: 'Food', color: '', icon: 'utensils' },
+ ] as unknown as Category[]
+
+ const TAGGED = buildPlace({ id: 1, category_id: 1 })
+ const BARE = buildPlace({ id: 2, category_id: null })
+ const TRACK = buildPlace({ id: 3, category_id: 2, route_geometry: '[[1,2],[3,4]]' })
+
-function renderSheet({ places = [TAGGED, BARE], categories = CATEGORIES, open = true }: {
++function renderSheet({ places = [TAGGED, BARE], categories = CATEGORIES, open = true, toursEnabled = false }: {
+ places?: Place[]
+ categories?: Category[]
+ open?: boolean
++ toursEnabled?: boolean
+ } = {}) {
+ const onClose = vi.fn()
- render(<MPlacesFilterSheet open={open} onClose={onClose} places={places} categories={categories} />)
++ render(<MPlacesFilterSheet open={open} onClose={onClose} places={places} categories={categories} toursEnabled={toursEnabled} />)
+ return { onClose }
+ }
+
+ const group = (name: string) => screen.getByRole('group', { name })
+
+ describe('MPlacesFilterSheet', () => {
+ beforeEach(() => {
+ resetAllStores()
+ })
+
+ it('FE-MOB-PFSHEET-001: shows the pool, the rating floors and the categories under one title', async () => {
+ renderSheet()
+ const sheet = await screen.findByRole('dialog', { name: 'Filters' })
+ expect(within(sheet).getByText('Show')).toBeInTheDocument()
+ expect(within(group('Show')).getAllByRole('button').map(b => b.textContent)).toEqual(['All', 'Unplanned', 'Planned'])
+ expect(within(group('Filter by rating')).getAllByRole('button').map(b => b.textContent))
+ .toEqual(['All', '5+', '4+', '3+', '2+', '1+'])
+ expect(screen.getByRole('checkbox', { name: 'Sights' })).toBeInTheDocument()
+ expect(screen.getByRole('checkbox', { name: 'Food' })).toBeInTheDocument()
+ expect(screen.getByRole('checkbox', { name: 'No Category' })).toBeInTheDocument()
+ })
+
+ it('FE-MOB-PFSHEET-002: the tracks pool only shows once a place carries a track', async () => {
+ renderSheet({ places: [TAGGED, TRACK] })
+ await screen.findByRole('dialog', { name: 'Filters' })
+ expect(within(group('Show')).getByRole('button', { name: 'Tracks' })).toBeInTheDocument()
+ expect(screen.queryByRole('checkbox', { name: 'No Category' })).not.toBeInTheDocument()
+ })
+
++ it('hides Tracks from the map filter while Tours is enabled', async () => {
++ const tourTrack = buildPlace({ id: 4, route_geometry: '[[5,6],[7,8]]' })
++ renderSheet({ places: [TAGGED, TRACK, tourTrack], toursEnabled: true })
++ await screen.findByRole('dialog', { name: 'Filters' })
++ expect(within(group('Show')).queryByRole('button', { name: 'Tracks' })).not.toBeInTheDocument()
++ })
++
+ it('FE-MOB-PFSHEET-003: picking a pool writes it to the trip store', async () => {
+ renderSheet()
+ await screen.findByRole('dialog', { name: 'Filters' })
+ const show = group('Show')
+ expect(within(show).getByRole('button', { name: 'All' })).toHaveAttribute('aria-pressed', 'true')
+ fireEvent.click(within(show).getByRole('button', { name: 'Unplanned' }))
+ expect(useTripStore.getState().placesFilter).toBe('unplanned')
+ // The chosen chip says so to a screen reader, and only that one.
+ expect(within(show).getByRole('button', { name: 'Unplanned' })).toHaveAttribute('aria-pressed', 'true')
+ expect(within(show).getByRole('button', { name: 'All' })).toHaveAttribute('aria-pressed', 'false')
+ })
+
+ it('FE-MOB-PFSHEET-004: picking a floor writes the rating filter to the trip store', async () => {
+ renderSheet()
+ await screen.findByRole('dialog', { name: 'Filters' })
+ const floors = group('Filter by rating')
+ fireEvent.click(within(floors).getByRole('button', { name: '3+' }))
+ expect(useTripStore.getState().placesRatingFilter).toBe(3)
+ expect(within(floors).getByRole('button', { name: '3+' })).toHaveAttribute('aria-pressed', 'true')
+ expect(within(floors).getByRole('button', { name: 'All' })).toHaveAttribute('aria-pressed', 'false')
+ })
+
+ it('FE-MOB-PFSHEET-005: categories toggle in and out of the shared set, "no category" included', async () => {
+ renderSheet()
+ await screen.findByRole('dialog', { name: 'Filters' })
+ fireEvent.click(screen.getByRole('checkbox', { name: 'Food' }))
+ fireEvent.click(screen.getByRole('checkbox', { name: 'No Category' }))
+ expect([...useTripStore.getState().placesCategoryFilter]).toEqual(['2', 'uncategorized'])
+ expect(screen.getByRole('checkbox', { name: 'Food' })).toHaveAttribute('aria-checked', 'true')
+ fireEvent.click(screen.getByRole('checkbox', { name: 'Food' }))
+ expect([...useTripStore.getState().placesCategoryFilter]).toEqual(['uncategorized'])
+ })
+
+ it('FE-MOB-PFSHEET-006: reset lifts every filter, and stays off while nothing filters', async () => {
+ seedStore(useTripStore, { placesFilter: 'planned', placesCategoryFilter: new Set(['1']), placesRatingFilter: 5 })
+ renderSheet()
+ await screen.findByRole('dialog', { name: 'Filters' })
+ const reset = screen.getByRole('button', { name: 'Reset' })
+ expect(reset).toBeEnabled()
+ fireEvent.click(reset)
+ const s = useTripStore.getState()
+ expect(s.placesFilter).toBe('all')
+ expect(s.placesCategoryFilter.size).toBe(0)
+ expect(s.placesRatingFilter).toBe('all')
+ expect(screen.getByRole('button', { name: 'Reset' })).toBeDisabled()
+ })
+
+ it('FE-MOB-PFSHEET-007: without any category to choose, the categories section is left out', async () => {
+ renderSheet({ places: [TAGGED], categories: [] })
+ const sheet = await screen.findByRole('dialog', { name: 'Filters' })
+ expect(within(sheet).queryByText('Categories')).not.toBeInTheDocument()
+ expect(screen.queryByRole('checkbox')).not.toBeInTheDocument()
+ })
+
+ it('FE-MOB-PFSHEET-008: the close button hands back to the caller', async () => {
+ const { onClose } = renderSheet()
+ fireEvent.click(within(await screen.findByRole('dialog', { name: 'Filters' })).getByRole('button', { name: 'Close' }))
+ expect(onClose).toHaveBeenCalledTimes(1)
+ })
+
+ it('FE-MOB-PFSHEET-009: nothing is rendered while closed', () => {
+ renderSheet({ open: false })
+ expect(screen.queryByRole('dialog', { name: 'Filters' })).not.toBeInTheDocument()
+ })
+ })