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.

places: offer a newer description in the refresh pill

Maurice8d8629516b0d
diff --git a/client/src/components/Planner/PlaceRefreshPill.tsx b/client/src/components/Planner/PlaceRefreshPill.tsx
index 390255b3f..1f4e708e5 100644
--- a/client/src/components/Planner/PlaceRefreshPill.tsx
+++ b/client/src/components/Planner/PlaceRefreshPill.tsx
@@ -10,6 +10,7 @@ import type { RefreshCandidate, RefreshField } from './placeRefresh';
type Translate = (key: string, params?: Record<string, string | number>) => string;
const LABEL: Record<RefreshField, string> = {
+ description: 'places.formDescription',
website: 'places.formWebsite',
phone: 'places.formPhone',
email: 'places.formEmail',
@@ -100,7 +101,7 @@ export function PlaceRefreshPill({
{t('places.refresh.now')}
</p>
{shown(c.field, c.current, locale, t).map((line) => (
- <p key={line} className="m-0 truncate">
+ <p key={line} className={c.field === 'description' ? 'm-0 line-clamp-3' : 'm-0 truncate'}>
{line}
</p>
))}
@@ -110,7 +111,7 @@ export function PlaceRefreshPill({
{t('places.refresh.new')}
</p>
{shown(c.field, c.next, locale, t).map((line) => (
- <p key={line} className="m-0 truncate">
+ <p key={line} className={c.field === 'description' ? 'm-0 line-clamp-3' : 'm-0 truncate'}>
{line}
</p>
))}
diff --git a/client/src/components/Planner/placeRefresh.test.ts b/client/src/components/Planner/placeRefresh.test.ts
index 2a46d7607..584fc4a4a 100644
--- a/client/src/components/Planner/placeRefresh.test.ts
+++ b/client/src/components/Planner/placeRefresh.test.ts
@@ -1,4 +1,4 @@
-// FE-PLANNER-REFRESH-001 to FE-PLANNER-REFRESH-005
+// FE-PLANNER-REFRESH-001 to FE-PLANNER-REFRESH-007
import { describe, expect, it } from 'vitest';
import { DEFAULT_FORM, type PlaceFormData } from './PlaceFormModal.helpers';
import { refreshCandidates } from './placeRefresh';
@@ -46,6 +46,24 @@ describe('refreshCandidates', () => {
expect(refreshCandidates(form({ opening_hours: hours?.next }), { opening_periods: PERIODS })).toEqual([]);
});
+ it('FE-PLANNER-REFRESH-006: a description comes from the index object or the OSM summary', () => {
+ const text = 'An Asian restaurant in Evershagen.';
+ expect(refreshCandidates(form(), { description: { text, source: 'community' } })).toEqual([
+ { field: 'description', current: '', next: text, preselected: true },
+ ]);
+ expect(refreshCandidates(form(), { summary: text, summary_source: 'community' })).toEqual([
+ { field: 'description', current: '', next: text, preselected: true },
+ ]);
+ });
+
+ it('FE-PLANNER-REFRESH-007: the same description under the editor markup is no difference', () => {
+ const text = 'An Asian restaurant in Evershagen.';
+ expect(refreshCandidates(form({ description: `<p>${text}</p>` }), { summary: text })).toEqual([]);
+ expect(refreshCandidates(form({ description: 'Our favourite.' }), { summary: text })).toEqual([
+ { field: 'description', current: 'Our favourite.', next: text, preselected: false },
+ ]);
+ });
+
it('FE-PLANNER-REFRESH-005: what the lookup does not know is never offered, so nothing is emptied', () => {
expect(refreshCandidates(form({ phone: '0381 1111', website: 'https://a.example' }), {})).toEqual([]);
expect(refreshCandidates(form(), null)).toEqual([]);
diff --git a/client/src/components/Planner/placeRefresh.ts b/client/src/components/Planner/placeRefresh.ts
index 8510ae4e6..5d20b807f 100644
--- a/client/src/components/Planner/placeRefresh.ts
+++ b/client/src/components/Planner/placeRefresh.ts
@@ -3,7 +3,7 @@ import type { PlaceFormData } from './PlaceFormModal.helpers';
import { cleanWeek, weekFromPeriods, writeWeek } from './placeHours';
/** The details a saved place can take over from a fresh lookup. */
-const REFRESH_FIELDS = ['website', 'phone', 'email', 'opening_hours'] as const;
+const REFRESH_FIELDS = ['description', 'website', 'phone', 'email', 'opening_hours'] as const;
export type RefreshField = (typeof REFRESH_FIELDS)[number];
/** One field where the lookup says something else than the place holds now. */
@@ -21,9 +21,22 @@ type Details = Record<string, unknown>;
const text = (value: unknown): string => (typeof value === 'string' ? value.trim() : '');
+/** A description as plain words: the editor stores markup, the lookup sends text. */
+const plain = (value: string): string =>
+ value
+ .replace(/<[^>]*>/g, ' ')
+ .replace(/[*_`~#>]/g, '')
+ .replace(/\s+/g, ' ')
+ .trim();
+
/** The lookup's value of a field, written the way the form stores it. */
function freshValue(field: RefreshField, details: Details): string {
if (field === 'website') return normalizePlaceWebsite(text(details.website)) ?? '';
+ // An index place carries its description as an object, an OSM place as the summary.
+ if (field === 'description') {
+ const own = details.description as { text?: unknown } | null | undefined;
+ return text(own?.text) || text(details.summary);
+ }
if (field === 'opening_hours') {
const week = weekFromPeriods(details.opening_periods as Parameters<typeof weekFromPeriods>[0]);
return week ? writeWeek(cleanWeek(week)) : '';
@@ -37,6 +50,7 @@ function sameValue(field: RefreshField, a: string, b: string): boolean {
if (field === 'website')
return (normalizePlaceWebsite(a) ?? a).replace(/\/$/, '').toLowerCase() === b.replace(/\/$/, '').toLowerCase();
if (field === 'email') return a.toLowerCase() === b.toLowerCase();
+ if (field === 'description') return plain(a) === plain(b);
if (field === 'opening_hours') {
const week = parsePlaceHours(a);
return (week ? writeWeek(cleanWeek(week)) : a) === b;