feat(tours): fill a city walk from a theme: culture, parks, food or a bit of everything (CW-05)

The search along the route offers a walk's own categories (sights, museums,
parks, views, coffee shops, places to eat, markets) and four themes that set
them at once. A found place says which theme brought it, its source and how
far it lies from the line, straight across; taken in as a stop, it keeps its
name and opening hours. Nothing is taken in without the existing confirm.
This commit is contained in:
Maurice
2026-10-19 22:44:54 +02:00
parent 290961cced
commit c97105ce61
31 changed files with 349 additions and 4 deletions
@@ -1,5 +1,5 @@
import type { TourPoi, TourPoiCategory } from '@trek/shared';
import { TOUR_POI_CORRIDORS_M } from '@trek/shared';
import type { TourPoi, TourPoiCategory, WalkTheme } from '@trek/shared';
import { TOUR_POI_CORRIDORS_M, WALK_THEMES } from '@trek/shared';
import {
AlertTriangle,
Clock,
@@ -150,12 +150,15 @@ function PoiRow({
planner,
insertion,
unit,
theme = null,
}: {
poi: TourPoi;
selected: boolean;
planner: TourPlannerController;
insertion: ReturnType<typeof usePoiInsertion>;
unit: Unit;
/** CW-05: the theme the place was suggested for, said as its reason. */
theme?: WalkTheme | null;
}) {
const { t } = useTranslation();
const select = useTourPoiStore((state) => state.select);
@@ -201,6 +204,7 @@ function PoiRow({
<div className="flex flex-col gap-2 px-2 pb-2.5">
<p className="m-0 flex flex-wrap gap-x-3 text-content-faint" style={fs(10.5, 'body')}>
<span>{t(look.labelKey)}</span>
{theme && <span>{t('tours.walk.themeReason', { theme: t(`tours.walk.theme.${theme}`) })}</span>}
<span>{t(poi.source === 'trek-places' ? 'tours.poi.source.trek' : 'tours.poi.source.osm')}</span>
</p>
{poi.address && (
@@ -307,6 +311,20 @@ export function TourPoiSearchCard({ planner }: { planner: TourPlannerController
<p className="m-0 text-content-faint" style={fs(11, 'body')}>
{t('tours.poi.intro')}
</p>
{search.themes.length > 0 && (
<div className="flex flex-col gap-1.5" data-testid="tour-poi-themes">
<Segmented<string>
fill
value={search.theme ?? ''}
onChange={(key) => search.chooseTheme(key as WalkTheme)}
label={t('tours.walk.themes')}
options={search.themes.map((key) => ({ value: key, label: t(`tours.walk.theme.${key}`) }))}
/>
<span className="text-content-faint" style={fs(11, 'body')}>
{search.theme ? t(`tours.walk.themeHint.${search.theme}`) : t('tours.walk.themeHint.own')}
</span>
</div>
)}
<div className="flex flex-wrap gap-1.5" role="group" aria-label={t('tours.poi.categories')}>
{search.offered.map((category) => (
<CategoryChip
@@ -363,6 +381,7 @@ export function TourPoiSearchCard({ planner }: { planner: TourPlannerController
planner={planner}
insertion={insertion}
unit={unit}
theme={search.theme && (WALK_THEMES[search.theme] as readonly string[]).includes(poi.category) ? search.theme : null}
/>
))}
</ul>
@@ -74,7 +74,15 @@ export function usePoiInsertion(planner: PoiInsertionPlanner) {
(poi: TourPoi) => {
const afterId = afterIdFor(poi);
if (!afterId || !planner.canEdit || planner.isSaving) return false;
const point: TourPlannerWaypoint = { id: randomId(), lat: poi.lat, lng: poi.lng, role: 'via' };
// The place keeps its name, and on a city walk its opening hours to check the arrival against (CW-04).
const point: TourPlannerWaypoint = {
id: randomId(),
lat: poi.lat,
lng: poi.lng,
role: 'via',
...(poi.name ? { name: poi.name } : {}),
...(poi.opening_hours ? { openingHours: poi.opening_hours } : {}),
};
const next = withPointAfter(planner.waypoints, afterId, point);
if (!next) return false;
const before = measuresOf(planner);
@@ -2,10 +2,13 @@ import {
TOUR_POI_CATEGORIES_BY_TYPE,
TOUR_POI_MAX_CATEGORIES,
TOUR_POI_MAX_LINE_POINTS,
WALK_THEME_KEYS,
WALK_THEMES,
type PlannableTourType,
type TourPoi,
type TourPoiCategory,
type TourPoiSearchResponse,
type WalkTheme,
} from '@trek/shared';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from '../../../i18n';
@@ -29,6 +32,10 @@ function thinned(line: Array<[number, number]>, most: number): Array<[number, nu
);
}
function sameSet(a: readonly string[], b: readonly string[]): boolean {
return a.length === b.length && a.every((item) => b.includes(item));
}
/** What a search was asked with, so a later change of the route or the choices shows it is out of date. */
function keyOf(route: Array<[number, number]> | null, type: string, categories: readonly string[], corridor: number) {
const ends = route && route.length > 1 ? [route[0], route[route.length - 1], route.length] : [];
@@ -64,6 +71,13 @@ export function useTourPoiSearch(planner: TourPoiPlanner) {
const currentKey = keyOf(route, type, categories, corridorM);
const canSearch = !!route && route.length > 1 && categories.length > 0 && loadingKey === null;
// CW-05: a city walk's theme is a set of its categories; the one the categories match exactly is the theme on.
const theme = type === 'walk' ? (WALK_THEME_KEYS.find((key) => sameSet(WALK_THEMES[key], categories)) ?? null) : null;
const chooseTheme = useCallback(
(key: WalkTheme) => setChosen((current) => ({ ...current, walk: [...WALK_THEMES[key]] })),
[]
);
const toggleCategory = useCallback(
(category: TourPoiCategory) =>
setChosen((current) => {
@@ -125,6 +139,10 @@ export function useTourPoiSearch(planner: TourPoiPlanner) {
offered: TOUR_POI_CATEGORIES_BY_TYPE[type],
categories,
toggleCategory,
/** CW-05: a city walk's themes; none for any other type. */
themes: type === 'walk' ? WALK_THEME_KEYS : [],
theme,
chooseTheme,
corridorM,
setCorridorM,
canSearch,