feat(tours): mark the best known places along a city walk

A search for sights along a tour now also asks the places index for the best
known places near the line, ranked by how often their Wikipedia articles are
read (QRank). A row the index already found is marked as a highlight; a
famous sight no kind names, like a square, is added as a sight of its own.
Stations, hotels and restaurants rank a row they match but are never added.

Highlights are listed first with a star in the list and a badge in the map
card. A place counts as a highlight from 40000 views a year, or the best
three from 5000 where fewer reach that. An index without ranks, or one older
than the endpoint, leaves the search as it was.
This commit is contained in:
Maurice
2026-10-20 12:16:11 +02:00
parent 54baf85a2a
commit 71fe69c1f1
45 changed files with 840 additions and 26 deletions
@@ -1,6 +1,6 @@
import type { TourPoi, WalkTheme } from '@trek/shared';
import { WALK_THEMES } from '@trek/shared';
import { Clock, ExternalLink, MoveHorizontal, Plus, Route, X } from 'lucide-react';
import { Clock, ExternalLink, MoveHorizontal, Plus, Route, Star, X } from 'lucide-react';
import { useCallback, useRef } from 'react';
import { useTranslation } from '../../../i18n';
import { useSettingsStore } from '../../../store/settingsStore';
@@ -9,7 +9,7 @@ import { formatDistance } from '../../../utils/units';
import { MAP_CARD_GLASS } from '../../Map/mapControlShadow';
import { TOUR_POI_LOOKS } from '../../Map/poiCategories';
import { useMapCardDismiss } from '../../Map/useMapCardDismiss';
import { WhiteBadge } from '../../Planner/planParts';
import { SoftPill, WhiteBadge } from '../../Planner/planParts';
import { PillSelect } from '../../shared/dialogParts';
import { fs } from '../../shared/DialogShell';
import type { TourPlannerController } from '../planner/useTourPlanner';
@@ -157,7 +157,22 @@ function TourPoiCard({
<h3 className="line-clamp-2 break-words font-semibold" style={fs(14, 'body')} title={poi.name || kind}>
{poi.name || kind}
</h3>
{poi.name && <p className="truncate text-caption text-content-muted">{kind}</p>}
{(poi.name || poi.highlight) && (
<div className="flex min-w-0 items-center gap-1.5">
{poi.name && <p className="min-w-0 truncate text-caption text-content-muted">{kind}</p>}
{/* One of the best known places along the route, as the star in the list marks it. */}
{poi.highlight && (
<span className="flex-none" title={t('tours.poi.highlightHint')} data-testid="tour-poi-highlight-badge">
<SoftPill
tone="warning"
icon={<Star size={10} strokeWidth={2.2} fill="currentColor" aria-hidden="true" />}
>
{t('tours.poi.highlight')}
</SoftPill>
</span>
)}
</div>
)}
</div>
<button
type="button"
@@ -10,6 +10,7 @@ import {
Route,
Search,
Shuffle,
Star,
Trees,
WifiOff,
X,
@@ -219,6 +220,18 @@ function PoiRow({ poi, selected, unit }: { poi: TourPoi; selected: boolean; unit
>
<look.Icon size={12} strokeWidth={2.2} />
</span>
{/* One of the best known places along the route: a star before its name. */}
{poi.highlight && (
<span
role="img"
aria-label={t('tours.poi.highlight')}
title={t('tours.poi.highlightHint')}
className="flex-none text-warning"
data-testid="tour-poi-highlight"
>
<Star size={12} strokeWidth={2.2} fill="currentColor" aria-hidden="true" />
</span>
)}
<span className="min-w-0 flex-1 truncate font-medium text-content" style={fs(12, 'body')}>
{poi.name || t(look.labelKey)}
</span>
@@ -14,7 +14,7 @@ import { usePoiInsertion, type PoiInsertionPlanner } from './usePoiInsertion';
import { useTourPoiMarkers } from './useTourPoiMarkers';
import { useTourPoiSearch } from './useTourPoiSearch';
// FE-TOUR-POI-001 to FE-TOUR-POI-016
// FE-TOUR-POI-001 to FE-TOUR-POI-018
vi.mock('../planner/useWaypointPlaceNames', () => ({ useWaypointPlaceNames: () => ({}) }));
@@ -288,6 +288,46 @@ describe('TourPoiSearchCard', () => {
});
});
describe('highlights along a tour', () => {
const SQUARE: TourPoi = {
...SPRING,
id: 'way:1',
name: 'Piazza San Marco',
category: 'sights',
kind: 'place=square',
opening_hours: null,
website: null,
highlight: true,
};
it('FE-TOUR-POI-017: a highlight carries a star before its name in the list, a place that is none carries none', async () => {
search.mockResolvedValue({ ...ANSWER, pois: [SQUARE, SPRING] });
render(<TourPoiSearchCard planner={searchPlanner()} />);
fireEvent.click(screen.getByTestId('tour-poi-search'));
const square = await screen.findByTestId('tour-poi-way:1');
const star = within(square).getByTestId('tour-poi-highlight');
expect(star).toHaveAttribute('aria-label', 'Highlight');
expect(star).toHaveAttribute('title', 'One of the best-known places here');
expect(within(square).getByRole('button', { name: /Highlight.*Piazza San Marco/ })).toBeInTheDocument();
expect(within(screen.getByTestId('tour-poi-node:1')).queryByTestId('tour-poi-highlight')).not.toBeInTheDocument();
});
it('FE-TOUR-POI-018: the card over the map says Highlight beside the kind, and only for a highlight', async () => {
search.mockResolvedValue({ ...ANSWER, pois: [SQUARE, SPRING] });
const planner = { ...searchPlanner(), ...insertionPlanner() } as unknown as TourPlannerController;
renderAlong(planner);
fireEvent.click(screen.getByTestId('tour-poi-search'));
fireEvent.click(within(await screen.findByTestId('tour-poi-way:1')).getByRole('button', { name: /Piazza/ }));
const badge = within(screen.getByTestId('tour-poi-overlay')).getByTestId('tour-poi-highlight-badge');
expect(badge).toHaveTextContent('Highlight');
expect(badge).toHaveAttribute('title', 'One of the best-known places here');
expect(screen.getByTestId('tour-poi-overlay')).toHaveTextContent('Sights');
fireEvent.click(within(screen.getByTestId('tour-poi-node:1')).getByRole('button', { name: /Spring/ }));
expect(screen.queryByTestId('tour-poi-highlight-badge')).not.toBeInTheDocument();
});
});
describe('a city walk along its places (CW-05)', () => {
const CAFE: TourPoi = {
...SPRING,