diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.json index 80083bf96..056c0e3ee 100644 --- a/client/scripts/size-baseline.json +++ b/client/scripts/size-baseline.json @@ -13,7 +13,7 @@ "src/components/Planner/DayPlanSidebar.test.tsx": 5349, "src/components/Planner/DayPlanSidebar.tsx": 2936, "src/components/Planner/PlaceFormModal.test.tsx": 2836, - "src/components/Planner/PlaceFormModal.tsx": 1157, + "src/components/Planner/PlaceFormModal.tsx": 1002, "src/components/Planner/PlaceInspector.tsx": 1290, "src/components/Studio/TravelElements.tsx": 1559, "src/components/Studio/countryShapes.ts": 2595, diff --git a/client/src/components/Planner/PlaceFormHeaderPills.tsx b/client/src/components/Planner/PlaceFormHeaderPills.tsx new file mode 100644 index 000000000..526961632 --- /dev/null +++ b/client/src/components/Planner/PlaceFormHeaderPills.tsx @@ -0,0 +1,220 @@ +import { Loader2, MapPin, Navigation, Plus, Search } from 'lucide-react'; +import { useEffect, useRef, useState, type ReactNode } from 'react'; +import type { Category, Place } from '../../types'; +import { safeHexColor } from '../../utils/safeColor'; +import type { StopKind } from '../Roadtrip/stopKinds'; +import { getCategoryIcon } from '../shared/categoryIcons'; +import { PillSelect } from '../shared/dialogParts'; +import { PILL } from '../shared/DialogShell'; +import { NavigationMenu } from '../shared/NavigationMenu'; +import { Tooltip } from '../shared/Tooltip'; +import { getNavigationTargets, openNavigationTarget } from './placeNavigation'; + +type Translate = (key: string, params?: Record) => string; + +/** The round pill of the head band: a + or a map pin, an icon and nothing else. */ +const ROUND_PILL_BUTTON = + 'grid h-[26px] w-[26px] flex-none place-items-center rounded-full bg-surface-card text-content-muted shadow-sm ring-1 ring-edge-faint transition-colors hover:text-content'; + +interface NewCategoryRow { + open: boolean; + setOpen: (open: boolean) => void; + name: string; + setName: (name: string) => void; + create: () => Promise; + inputId: string; +} + +/** + * The head band's pill row. The category to pick, with a round + beside it that + * turns the two into a field for a new one; for a stop on a drive, its kind in + * place of both. Then where the picked place came from, and a spinner while a + * pick is still being looked up. + */ +export function HeaderPills({ + kind, + categories, + categoryId, + onCategory, + newCategory, + pickedSource, + busy, + navPlace, + refresh, + t, +}: { + kind?: StopKind; + categories: Category[] | null; + categoryId: string; + onCategory: (id: string) => void; + newCategory: NewCategoryRow; + pickedSource: string | null; + busy: boolean; + /** The place as the form holds it, once it has a position: opens it in a map app (#2178). */ + navPlace: NavigablePlace | null; + /** Newer details for a saved place, when a fresh lookup has them (PlaceRefreshPill). */ + refresh?: ReactNode; + t: Translate; +}) { + // When the new-category field closes, the field or the button that closed it + // goes with it, and the focus would drop out of the dialog. It comes back to + // the + that opened the field, as a picker's focus comes back to its pill. + const plusRef = useRef(null); + const wasOpen = useRef(newCategory.open); + useEffect(() => { + const closed = wasOpen.current && !newCategory.open; + wasOpen.current = newCategory.open; + if (!closed) return; + const active = document.activeElement; + if (!active || active === document.body || !active.isConnected) plusRef.current?.focus(); + }, [newCategory.open]); + + const noCategory = { + label: t('places.noCategory'), + icon: , + }; + const options = [ + { value: '', ...noCategory }, + ...(categories || []).map((c) => { + const Icon = getCategoryIcon(c.icon); + // A string like form.category_id, so the picked option hands back the same + // kind of value the form already keeps. + return { + value: String(c.id), + label: c.name, + icon: , + }; + }), + ]; + + let lead: ReactNode; + if (kind) { + lead = ( + + + {t(kind.labelKey)} + + ); + } else if (newCategory.open) { + lead = ; + } else { + lead = ( + <> + + + + + + ); + } + + return ( + <> + {lead} + {pickedSource && ( + + + )} + {navPlace && } + {refresh} + {busy && ( + + + )} + + ); +} + +type NavigablePlace = Pick; + +/** + * A look at the picked place in a real map before it is saved (#2178): its reviews, its + * photos, whether it is the right branch. The same apps the inspector offers, one tap + * straight away when only one applies. + */ +function OpenInMapsPill({ place, t }: { place: NavigablePlace; t: Translate }) { + const [open, setOpen] = useState(false); + const anchorRef = useRef(null); + const targets = getNavigationTargets(place); + if (targets.length === 0) return null; + return ( + + + + + {open && setOpen(false)} />} + + ); +} + +/** The new category's name, typed where the category pill was, with its OK and Cancel beside it. */ +function NewCategoryField({ inputId, name, setName, create, setOpen, t }: NewCategoryRow & { t: Translate }) { + return ( + // One parent for the field and both of its buttons. + + setName(e.target.value)} + onKeyDown={(e) => { + // Enter confirms the name, like OK; it never reaches the place's own save. + if (e.key === 'Enter') { + e.preventDefault(); + void create(); + } + // Escape closes the field, like Cancel, and only the field: marked + // handled, the dialog around it leaves it alone and keeps what is typed. + if (e.key === 'Escape') { + e.preventDefault(); + setOpen(false); + } + }} + aria-label={t('places.newCategory')} + placeholder={t('places.categoryNamePlaceholder')} + className="w-48 min-w-0 rounded-full bg-surface-card px-3 py-1 text-content shadow-sm outline-none ring-1 ring-edge-faint placeholder:text-content-faint focus:ring-2 focus:ring-[color:var(--text-primary)]" + /> + + + + ); +} diff --git a/client/src/components/Planner/PlaceFormModal.tsx b/client/src/components/Planner/PlaceFormModal.tsx index 1ac99cfbe..61feeadfd 100644 --- a/client/src/components/Planner/PlaceFormModal.tsx +++ b/client/src/components/Planner/PlaceFormModal.tsx @@ -12,7 +12,7 @@ import { PendingFiles, PlaceImageSection } from './PlaceFormMedia' import { usePlaceImageField } from './usePlaceImageField' import { useToast } from '../shared/Toast' import { Tooltip } from '../shared/Tooltip' -import { Search, Loader2, Plus, RotateCcw, MapPin, Navigation, LocateFixed, PencilLine } from 'lucide-react' +import { Search, RotateCcw, LocateFixed, PencilLine } from 'lucide-react' import { useTranslation } from '../../i18n' import { PlaceContactFields } from './PlaceContactFields' import { weekFromPeriods } from './placeHours' @@ -24,8 +24,6 @@ import { import { useNewCategory, usePlaceForm } from './usePlaceForm' import { usePlaceSearch } from './usePlaceSearch' import { guessCategoryId } from '@trek/shared' -import { getNavigationTargets, openNavigationTarget } from './placeNavigation' -import { NavigationMenu } from '../shared/NavigationMenu' import { offersGoogleRetry } from '../../utils/placeSource' import { safeHexColor } from '../../utils/safeColor' import { useLocationBias } from '../../hooks/useLocationBias' @@ -36,14 +34,17 @@ import { NumericInput } from '../shared/NumericInput' import { formatDistance } from '../../utils/units' import ServiceStopSection from '../Roadtrip/ServiceStopSection' import { DEFAULT_SERVICE_KIND, serviceStopChoice, type ServiceStopMode } from '../Roadtrip/manualStop' -import { STOP_KIND_BY_KEY, type StopKind } from '../Roadtrip/stopKinds' +import { STOP_KIND_BY_KEY } from '../Roadtrip/stopKinds' import { getCategoryIcon } from '../shared/categoryIcons' import { - DialogShell, DialogHeader, DialogTile, DialogSection, DialogFooter, FooterSpacer, DialogButton, NEUTRAL_TINT, PILL, fs, + DialogShell, DialogHeader, DialogTile, DialogSection, DialogFooter, FooterSpacer, DialogButton, NEUTRAL_TINT, fs, } from '../shared/DialogShell' -import { EditorField, GRID_2, INPUT, LABEL, PANEL, PillSelect, TEXTAREA } from '../shared/dialogParts' +import { EditorField, GRID_2, INPUT, LABEL, PANEL, TEXTAREA } from '../shared/dialogParts' import { SoftPill, tintOf } from './planParts' import { TimeSection } from './PlaceFormTimeSection' +import { HeaderPills } from './PlaceFormHeaderPills' +import { PlaceRefreshPill } from './PlaceRefreshPill' +import { usePlaceRefresh } from './usePlaceRefresh' // The submit payload mirrors the form, but lat/lng are parsed to numbers and // category_id is normalised, plus any files chosen before the place existed. @@ -278,6 +279,7 @@ function usePlaceFormModal(props: PlaceFormModalProps) { setPickedSource(null) }, }) + const refresh = usePlaceRefresh({ place, form, language: search.language }) /** * What a stop on a drive might be a second copy of, said while the form is being filled. @@ -425,6 +427,7 @@ function usePlaceFormModal(props: PlaceFormModalProps) { t, language: search.language, locale, + refresh, timeFormat, googleAnswers: search.googleAnswers, placesEnrichEnabled, @@ -484,7 +487,6 @@ const SIDE_BUTTON = 'grid w-[38px] flex-none place-items-center rounded-[10px] t */ const SERVICE_STOP_LABELS = '[&_label]:mb-[5px] [&_label]:block [&_label]:font-geist [&_label]:text-[length:calc(9.5px*var(--fs-scale-caption,1))] [&_label]:font-bold [&_label]:uppercase [&_label]:tracking-[.08em] [&_label]:text-content-faint' /** A round white button in the head band's pill row, as tall as the pills beside it. */ -const ROUND_PILL_BUTTON = 'grid h-[26px] w-[26px] flex-none place-items-center rounded-full bg-surface-card text-content-muted shadow-sm ring-1 ring-edge-faint transition-colors hover:text-content' type Translate = (key: string, params?: Record) => string @@ -570,6 +572,7 @@ export default function PlaceFormModal(props: PlaceFormModalProps) { inputId: `${fieldId}-new-category`, }} pickedSource={S.pickedSource} + refresh={} busy={isSearchingMaps} navPlace={form.lat && form.lng ? { name: form.name, address: form.address, lat: Number(form.lat), lng: Number(form.lng), @@ -947,154 +950,6 @@ export default function PlaceFormModal(props: PlaceFormModalProps) { ) } -interface NewCategoryRow { - open: boolean - setOpen: (open: boolean) => void - name: string - setName: (name: string) => void - create: () => Promise - inputId: string -} - -/** - * The head band's pill row. The category to pick, with a round + beside it that - * turns the two into a field for a new one; for a stop on a drive, its kind in - * place of both. Then where the picked place came from, and a spinner while a - * pick is still being looked up. - */ -function HeaderPills({ kind, categories, categoryId, onCategory, newCategory, pickedSource, busy, navPlace, t }: { - kind?: StopKind - categories: Category[] | null - categoryId: string - onCategory: (id: string) => void - newCategory: NewCategoryRow - pickedSource: string | null - busy: boolean - /** The place as the form holds it, once it has a position: opens it in a map app (#2178). */ - navPlace: NavigablePlace | null - t: Translate -}) { - // When the new-category field closes, the field or the button that closed it - // goes with it, and the focus would drop out of the dialog. It comes back to - // the + that opened the field, as a picker's focus comes back to its pill. - const plusRef = useRef(null) - const wasOpen = useRef(newCategory.open) - useEffect(() => { - const closed = wasOpen.current && !newCategory.open - wasOpen.current = newCategory.open - if (!closed) return - const active = document.activeElement - if (!active || active === document.body || !active.isConnected) plusRef.current?.focus() - }, [newCategory.open]) - - const noCategory = { label: t('places.noCategory'), icon: } - const options = [ - { value: '', ...noCategory }, - ...(categories || []).map(c => { - const Icon = getCategoryIcon(c.icon) - // A string like form.category_id, so the picked option hands back the same - // kind of value the form already keeps. - return { value: String(c.id), label: c.name, icon: } - }), - ] - - let lead: ReactNode - if (kind) { - lead = {t(kind.labelKey)} - } else if (newCategory.open) { - lead = - } else { - lead = ( - <> - - - - - - ) - } - - return ( - <> - {lead} - {pickedSource && ( - - - )} - {navPlace && } - {busy && ( - - - )} - - ) -} - -type NavigablePlace = Pick - -/** - * A look at the picked place in a real map before it is saved (#2178): its reviews, its - * photos, whether it is the right branch. The same apps the inspector offers, one tap - * straight away when only one applies. - */ -function OpenInMapsPill({ place, t }: { place: NavigablePlace; t: Translate }) { - const [open, setOpen] = useState(false) - const anchorRef = useRef(null) - const targets = getNavigationTargets(place) - if (targets.length === 0) return null - return ( - - - - - {open && setOpen(false)} />} - - ) -} - -/** The new category's name, typed where the category pill was, with its OK and Cancel beside it. */ -function NewCategoryField({ inputId, name, setName, create, setOpen, t }: NewCategoryRow & { t: Translate }) { - return ( - // One parent for the field and both of its buttons. - - setName(e.target.value)} - onKeyDown={e => { - // Enter confirms the name, like OK; it never reaches the place's own save. - if (e.key === 'Enter') { e.preventDefault(); void create() } - // Escape closes the field, like Cancel, and only the field: marked - // handled, the dialog around it leaves it alone and keeps what is typed. - if (e.key === 'Escape') { e.preventDefault(); setOpen(false) } - }} - aria-label={t('places.newCategory')} - placeholder={t('places.categoryNamePlaceholder')} - className="w-48 min-w-0 rounded-full bg-surface-card px-3 py-1 text-content shadow-sm outline-none ring-1 ring-edge-faint placeholder:text-content-faint focus:ring-2 focus:ring-[color:var(--text-primary)]" - /> - - - - ) -} - /** A Markdown field: its label, the formatting bar on the same line, the text under both. */ function MarkdownField({ id, label, value, onChange, placeholder, maxLength }: { id: string diff --git a/client/src/components/Planner/PlaceRefreshPill.test.tsx b/client/src/components/Planner/PlaceRefreshPill.test.tsx new file mode 100644 index 000000000..77af6ea3a --- /dev/null +++ b/client/src/components/Planner/PlaceRefreshPill.test.tsx @@ -0,0 +1,39 @@ +// FE-PLANNER-REFRESHPILL-001 to FE-PLANNER-REFRESHPILL-003 +import userEvent from '@testing-library/user-event'; +import { describe, expect, it, vi } from 'vitest'; +import { render, screen, within } from '../../../tests/helpers/render'; +import { PlaceRefreshPill } from './PlaceRefreshPill'; +import type { RefreshCandidate } from './placeRefresh'; + +const t = (key: string) => key; + +const CANDIDATES: RefreshCandidate[] = [ + { field: 'phone', current: '', next: '+49 381 87398063', preselected: true }, + { field: 'website', current: 'https://old.example', next: 'https://www.thao-vinh.de/', preselected: false }, +]; + +describe('PlaceRefreshPill', () => { + it('FE-PLANNER-REFRESHPILL-001: nothing shows while the details match the place', () => { + const { container } = render(); + expect(container).toBeEmptyDOMElement(); + }); + + it('FE-PLANNER-REFRESHPILL-002: the pill counts the differences; empty fields are ticked, filled ones say they replace', async () => { + render(); + const pill = screen.getByRole('button', { name: /places\.refresh\.pill/ }); + expect(within(pill).getByText('2')).toBeInTheDocument(); + await userEvent.click(pill); + expect(screen.getByRole('button', { name: 'places.formPhone' })).toHaveAttribute('aria-pressed', 'true'); + expect(screen.getByRole('button', { name: 'places.formWebsite' })).toHaveAttribute('aria-pressed', 'false'); + expect(screen.getByText('places.refresh.replaces')).toBeInTheDocument(); + }); + + it('FE-PLANNER-REFRESHPILL-003: confirming takes over only the ticked fields, with the provider as origin', async () => { + const onApply = vi.fn(); + render(); + await userEvent.click(screen.getByRole('button', { name: /places\.refresh\.pill/ })); + await userEvent.click(screen.getByRole('button', { name: 'places.refresh.apply' })); + expect(onApply).toHaveBeenCalledTimes(1); + expect(onApply).toHaveBeenCalledWith('phone', '+49 381 87398063', 'osm'); + }); +}); diff --git a/client/src/components/Planner/PlaceRefreshPill.tsx b/client/src/components/Planner/PlaceRefreshPill.tsx new file mode 100644 index 000000000..390255b3f --- /dev/null +++ b/client/src/components/Planner/PlaceRefreshPill.tsx @@ -0,0 +1,132 @@ +import type { PlaceClientOrigin } from '@trek/shared'; +import { RefreshCw } from 'lucide-react'; +import { useState } from 'react'; +import ToggleSwitch from '../Settings/ToggleSwitch'; +import ConfirmDialog from '../shared/ConfirmDialog'; +import { fs, PILL } from '../shared/DialogShell'; +import { hoursLines } from './placeHours'; +import type { RefreshCandidate, RefreshField } from './placeRefresh'; + +type Translate = (key: string, params?: Record) => string; + +const LABEL: Record = { + website: 'places.formWebsite', + phone: 'places.formPhone', + email: 'places.formEmail', + opening_hours: 'inspector.openingHours', +}; + +/** A value as the list shows it: hours as one line per day, the rest as stored. */ +function shown(field: RefreshField, value: string, locale: string | undefined, t: Translate): string[] { + if (!value) return [t('places.refresh.empty')]; + if (field === 'opening_hours') return hoursLines(value, locale, t('places.hoursClosed')) ?? [value]; + return [value]; +} + +/** + * A saved place's details that TREK knows better now: a pill in the head band + * when a fresh lookup differs from what the place holds, and a list to pick + * from. An empty field is ticked, a filled one is the person's to decide, and + * nothing is taken over before they confirm. The form saves as usual after. + */ +export function PlaceRefreshPill({ + candidates, + origin, + onApply, + locale, + t, +}: { + candidates: RefreshCandidate[]; + origin: PlaceClientOrigin; + /** Sets one field in the form, with the provider as its origin. */ + onApply: (field: RefreshField, value: string, origin: PlaceClientOrigin) => void; + locale?: string; + t: Translate; +}) { + const [open, setOpen] = useState(false); + const [picked, setPicked] = useState>(new Set()); + if (candidates.length === 0) return null; + + const show = () => { + setPicked(new Set(candidates.filter((c) => c.preselected).map((c) => c.field))); + setOpen(true); + }; + const toggle = (field: RefreshField) => + setPicked((now) => { + const next = new Set(now); + if (next.has(field)) next.delete(field); + else next.add(field); + return next; + }); + const apply = () => { + for (const c of candidates) if (picked.has(c.field)) onApply(c.field, c.next, origin); + setOpen(false); + }; + + return ( + <> + + setOpen(false)} + onConfirm={apply} + title={t('places.refresh.title')} + message={t('places.refresh.intro')} + confirmLabel={t('places.refresh.apply')} + danger={false} + > +
    + {candidates.map((c) => ( +
  • +
    +

    + {t(LABEL[c.field])} +

    +
    +
    +

    + {t('places.refresh.now')} +

    + {shown(c.field, c.current, locale, t).map((line) => ( +

    + {line} +

    + ))} +
    +
    +

    + {t('places.refresh.new')} +

    + {shown(c.field, c.next, locale, t).map((line) => ( +

    + {line} +

    + ))} +
    +
    + {!c.preselected && ( +

    + {t('places.refresh.replaces')} +

    + )} +
    + toggle(c.field)} /> +
  • + ))} +
+
+ + ); +} diff --git a/client/src/components/Planner/placeRefresh.test.ts b/client/src/components/Planner/placeRefresh.test.ts new file mode 100644 index 000000000..2a46d7607 --- /dev/null +++ b/client/src/components/Planner/placeRefresh.test.ts @@ -0,0 +1,53 @@ +// FE-PLANNER-REFRESH-001 to FE-PLANNER-REFRESH-005 +import { describe, expect, it } from 'vitest'; +import { DEFAULT_FORM, type PlaceFormData } from './PlaceFormModal.helpers'; +import { refreshCandidates } from './placeRefresh'; + +const form = (over: Partial = {}): PlaceFormData => ({ ...DEFAULT_FORM, ...over }); + +// Mo-Fr 10:30-20:00, as the details lookup hands periods out (day 0 is Sunday). +const PERIODS = [1, 2, 3, 4, 5].map((day) => ({ + open: { day, hour: 10, minute: 30 }, + close: { day, hour: 20, minute: 0 }, +})); + +describe('refreshCandidates', () => { + it('FE-PLANNER-REFRESH-001: an empty field the lookup fills is offered and ticked', () => { + const got = refreshCandidates(form(), { phone: '+49 381 87398063', website: 'www.thao-vinh.de' }); + expect(got).toEqual([ + expect.objectContaining({ field: 'website', current: '', preselected: true }), + expect.objectContaining({ field: 'phone', current: '', next: '+49 381 87398063', preselected: true }), + ]); + expect(got[0]?.next).toMatch(/^https:\/\/www\.thao-vinh\.de\/?$/); + }); + + it('FE-PLANNER-REFRESH-002: a value the person has is offered only when it differs, and not ticked', () => { + const got = refreshCandidates(form({ phone: '0381 1111' }), { phone: '+49 381 2222' }); + expect(got).toEqual([{ field: 'phone', current: '0381 1111', next: '+49 381 2222', preselected: false }]); + }); + + it('FE-PLANNER-REFRESH-003: the same value in another spelling is no difference', () => { + expect( + refreshCandidates( + form({ phone: '+49 381 873 98 063', website: 'https://www.helgas-kitchen.de/', email: 'Info@Luna.de' }), + { + phone: '+4938187398063', + website: 'https://www.helgas-kitchen.de', + email: 'info@luna.de', + } + ) + ).toEqual([]); + }); + + it('FE-PLANNER-REFRESH-004: hours come as the stored week, and the same week is no difference', () => { + const [hours] = refreshCandidates(form(), { opening_periods: PERIODS }); + expect(hours?.field).toBe('opening_hours'); + expect(JSON.parse(hours?.next ?? '[]')).toHaveLength(7); + expect(refreshCandidates(form({ opening_hours: hours?.next }), { opening_periods: PERIODS })).toEqual([]); + }); + + 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 new file mode 100644 index 000000000..0f99f1f6d --- /dev/null +++ b/client/src/components/Planner/placeRefresh.ts @@ -0,0 +1,63 @@ +import { normalizePlaceWebsite, parsePlaceHours } from '@trek/shared'; +import type { PlaceFormData } from './PlaceFormModal.helpers'; +import { cleanWeek, weekFromPeriods, writeWeek } from './placeHours'; + +/** The details a saved place can take over from a fresh lookup. */ +export const REFRESH_FIELDS = ['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. */ +export interface RefreshCandidate { + field: RefreshField; + /** What the form holds, as stored; empty when it holds nothing. */ + current: string; + /** What the lookup has, in the form's own format (hours as the stored week). */ + next: string; + /** An empty field takes the new value without asking; a filled one is the person's call. */ + preselected: boolean; +} + +type Details = Record; + +const text = (value: unknown): string => (typeof value === 'string' ? value.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)) ?? ''; + if (field === 'opening_hours') { + const week = weekFromPeriods(details.opening_periods as Parameters[0]); + return week ? writeWeek(cleanWeek(week)) : ''; + } + return text(details[field]); +} + +/** Two values that say the same in a different spelling count as one. */ +function sameValue(field: RefreshField, a: string, b: string): boolean { + if (field === 'phone') return a.replace(/[^\d+]/g, '') === b.replace(/[^\d+]/g, ''); + if (field === 'website') + return (normalizePlaceWebsite(a) ?? a).replace(/\/$/, '').toLowerCase() === b.replace(/\/$/, '').toLowerCase(); + if (field === 'email') return a.toLowerCase() === b.toLowerCase(); + if (field === 'opening_hours') { + const week = parsePlaceHours(a); + return (week ? writeWeek(cleanWeek(week)) : a) === b; + } + return a === b; +} + +/** + * The fields where a fresh lookup of a saved place differs from what the form + * holds. A field the lookup knows nothing about is never offered: refreshing + * must not empty what the place already has. + */ +export function refreshCandidates(form: PlaceFormData, details: Details | null | undefined): RefreshCandidate[] { + if (!details) return []; + const out: RefreshCandidate[] = []; + for (const field of REFRESH_FIELDS) { + const next = freshValue(field, details); + if (!next) continue; + const current = (form[field] ?? '').trim(); + if (current && sameValue(field, current, next)) continue; + out.push({ field, current, next, preselected: current === '' }); + } + return out; +} diff --git a/client/src/components/Planner/usePlaceRefresh.ts b/client/src/components/Planner/usePlaceRefresh.ts new file mode 100644 index 000000000..92e0da002 --- /dev/null +++ b/client/src/components/Planner/usePlaceRefresh.ts @@ -0,0 +1,51 @@ +import type { PlaceClientOrigin } from '@trek/shared'; +import { useEffect, useMemo, useState } from 'react'; +import { mapsApi } from '../../api/client'; +import type { Place } from '../../types'; +import type { PlaceFormData } from './PlaceFormModal.helpers'; +import { resultOrigin } from './placeFieldOrigins'; +import { refreshCandidates, type RefreshCandidate } from './placeRefresh'; + +/** The id the details lookup takes for a saved place: its Google id, else its OSM or index id. */ +function detailIdOf(place: Place | null | undefined): string | null { + if (!place) return null; + return place.google_place_id || place.osm_id || null; +} + +/** + * Fresh details for a place being edited, and the fields where they differ + * from the form. Asked once per opened place and language; a place without a + * provider id, and a new place, have nothing to refresh from. + */ +export function usePlaceRefresh({ + place, + form, + language, +}: { + place: Place | null | undefined; + form: PlaceFormData; + language: string; +}): { candidates: RefreshCandidate[]; origin: PlaceClientOrigin } { + const detailId = detailIdOf(place); + // Keyed by what was asked, so a stale answer for another place is never read. + const [fresh, setFresh] = useState<{ key: string; details: Record } | null>(null); + const key = detailId ? `${detailId}|${language}` : null; + + useEffect(() => { + if (!detailId || !key) return; + let live = true; + mapsApi.details(detailId, language).then( + (answer: { place?: Record | null }) => { + if (live && answer?.place) setFresh({ key, details: answer.place }); + }, + () => undefined + ); + return () => { + live = false; + }; + }, [detailId, key, language]); + + const details = fresh && fresh.key === key ? fresh.details : null; + const candidates = useMemo(() => refreshCandidates(form, details), [form, details]); + return { candidates, origin: details ? resultOrigin(details) : 'enrichment' }; +} diff --git a/shared/src/i18n/ar/places.ts b/shared/src/i18n/ar/places.ts index 3e1dac8aa..3726b3709 100644 --- a/shared/src/i18n/ar/places.ts +++ b/shared/src/i18n/ar/places.ts @@ -206,5 +206,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'تحتاج الصورة الجديدة إلى اتصال. احفظ مجددًا عند الاتصال بالإنترنت.', 'places.openPhotos': 'عرض الصور', 'places.imageUploadError': 'تعذّر رفع الصورة', + 'places.refresh.pill': 'تفاصيل جديدة للمكان', + 'places.refresh.title': 'تحديث تفاصيل المكان', + 'places.refresh.intro': + 'يعرف TREK تفاصيل أحدث لهذا المكان. اختر ما تريد اعتماده، ويبقى الباقي كما هو. احفظ المكان بعد ذلك.', + 'places.refresh.apply': 'اعتماد', + 'places.refresh.replaces': 'يستبدل القيمة المحفوظة الآن', + 'places.refresh.empty': 'فارغ', + 'places.refresh.now': 'الآن', + 'places.refresh.new': 'جديد', }; export default places; diff --git a/shared/src/i18n/az/places.ts b/shared/src/i18n/az/places.ts index 9177f9294..70dd86f36 100644 --- a/shared/src/i18n/az/places.ts +++ b/shared/src/i18n/az/places.ts @@ -188,6 +188,15 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Yeni şəkil üçün bağlantı lazımdır. Onlayn olanda yenidən yadda saxla.', 'places.openPhotos': 'Fotolara bax', 'places.imageUploadError': 'Şəkli yükləmək mümkün olmadı', + 'places.refresh.pill': 'Yeni məkan məlumatları', + 'places.refresh.title': 'Məkan məlumatlarını yenilə', + 'places.refresh.intro': + 'TREK bu məkan haqqında daha yeni məlumatlar bilir. Nəyi götürəcəyinizi seçin, qalanı olduğu kimi qalır. Sonra məkanı yadda saxlayın.', + 'places.refresh.apply': 'Götür', + 'places.refresh.replaces': 'Hazırda saxlanılanı əvəz edir', + 'places.refresh.empty': 'boş', + 'places.refresh.now': 'İndi', + 'places.refresh.new': 'Yeni', }; export default places; diff --git a/shared/src/i18n/br/places.ts b/shared/src/i18n/br/places.ts index 90ec5e29c..8007bdb98 100644 --- a/shared/src/i18n/br/places.ts +++ b/shared/src/i18n/br/places.ts @@ -174,5 +174,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Uma nova imagem precisa de conexão. Salve de novo quando estiver online.', 'places.openPhotos': 'Ver fotos', 'places.imageUploadError': 'Não foi possível enviar a imagem', + 'places.refresh.pill': 'Novos dados do lugar', + 'places.refresh.title': 'Atualizar dados do lugar', + 'places.refresh.intro': + 'O TREK conhece dados mais recentes deste lugar. Escolha o que quer adotar; o resto fica como está. Salve o lugar depois.', + 'places.refresh.apply': 'Adotar', + 'places.refresh.replaces': 'Substitui o que está salvo agora', + 'places.refresh.empty': 'vazio', + 'places.refresh.now': 'Agora', + 'places.refresh.new': 'Novo', }; export default places; diff --git a/shared/src/i18n/ca/places.ts b/shared/src/i18n/ca/places.ts index 00febb4c5..2b25d35a6 100644 --- a/shared/src/i18n/ca/places.ts +++ b/shared/src/i18n/ca/places.ts @@ -176,5 +176,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Una imatge nova necessita connexió. Torna a desar quan estiguis en línia.', 'places.openPhotos': 'Mostra les fotos', 'places.imageUploadError': "No s'ha pogut pujar la imatge", + 'places.refresh.pill': 'Dades noves del lloc', + 'places.refresh.title': 'Actualitza les dades del lloc', + 'places.refresh.intro': + "TREK coneix dades més noves d'aquest lloc. Tria què vols adoptar; la resta es queda com està. Després desa el lloc.", + 'places.refresh.apply': 'Adopta', + 'places.refresh.replaces': 'Substitueix el que hi ha desat ara', + 'places.refresh.empty': 'buit', + 'places.refresh.now': 'Ara', + 'places.refresh.new': 'Nou', }; export default places; diff --git a/shared/src/i18n/cs/places.ts b/shared/src/i18n/cs/places.ts index c5adfdb6d..46fb45ac1 100644 --- a/shared/src/i18n/cs/places.ts +++ b/shared/src/i18n/cs/places.ts @@ -182,5 +182,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Nový obrázek potřebuje připojení. Ulož znovu, až budeš online.', 'places.openPhotos': 'Zobrazit fotky', 'places.imageUploadError': 'Obrázek se nepodařilo nahrát', + 'places.refresh.pill': 'Nové údaje o místě', + 'places.refresh.title': 'Aktualizovat údaje o místě', + 'places.refresh.intro': + 'TREK zná novější údaje o tomto místě. Vyberte, co chcete převzít, zbytek zůstane beze změny. Potom místo uložte.', + 'places.refresh.apply': 'Převzít', + 'places.refresh.replaces': 'Nahradí aktuálně uloženou hodnotu', + 'places.refresh.empty': 'prázdné', + 'places.refresh.now': 'Nyní', + 'places.refresh.new': 'Nové', }; export default places; diff --git a/shared/src/i18n/de/places.ts b/shared/src/i18n/de/places.ts index 861a1a1c2..24e8237e5 100644 --- a/shared/src/i18n/de/places.ts +++ b/shared/src/i18n/de/places.ts @@ -174,5 +174,14 @@ const places: TranslationStrings = { 'Sucht jeden importierten Ort nach, um Fotos, Adresse und Kontaktdaten zu ergänzen. Nutzt deinen Google-Maps-Key.', 'places.enrichOnImportFileHint': 'Sucht jeden importierten Punkt danach bei Google und ergänzt Foto, Adresse, Website und Telefonnummer. Pfade und Tracks bleiben, wie sie sind.', + 'places.refresh.pill': 'Neue Ortsdaten', + 'places.refresh.title': 'Ortsdaten aktualisieren', + 'places.refresh.intro': + 'TREK kennt neuere Angaben zu diesem Ort. Wähle, was du übernehmen willst, der Rest bleibt, wie er ist. Danach den Ort speichern.', + 'places.refresh.apply': 'Übernehmen', + 'places.refresh.replaces': 'Ersetzt den gespeicherten Wert', + 'places.refresh.empty': 'leer', + 'places.refresh.now': 'Jetzt', + 'places.refresh.new': 'Neu', }; export default places; diff --git a/shared/src/i18n/en/places.ts b/shared/src/i18n/en/places.ts index 5de82e80c..712eeeeff 100644 --- a/shared/src/i18n/en/places.ts +++ b/shared/src/i18n/en/places.ts @@ -181,5 +181,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'A new picture needs a connection. Save again once you are online.', 'places.openPhotos': 'Show photos', 'places.imageUploadError': 'Could not upload image', + 'places.refresh.pill': 'New place details', + 'places.refresh.title': 'Update place details', + 'places.refresh.intro': + 'TREK knows newer details for this place. Pick what to take over; the rest stays as it is. Save the place afterwards.', + 'places.refresh.apply': 'Take over', + 'places.refresh.replaces': 'Replaces what is saved now', + 'places.refresh.empty': 'empty', + 'places.refresh.now': 'Now', + 'places.refresh.new': 'New', }; export default places; diff --git a/shared/src/i18n/es/places.ts b/shared/src/i18n/es/places.ts index b9e823d94..88eac75aa 100644 --- a/shared/src/i18n/es/places.ts +++ b/shared/src/i18n/es/places.ts @@ -175,5 +175,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Una imagen nueva necesita conexión. Guarda de nuevo cuando estés en línea.', 'places.openPhotos': 'Ver fotos', 'places.imageUploadError': 'No se pudo subir la imagen', + 'places.refresh.pill': 'Datos nuevos del lugar', + 'places.refresh.title': 'Actualizar datos del lugar', + 'places.refresh.intro': + 'TREK conoce datos más recientes de este lugar. Elige qué quieres adoptar; el resto se queda como está. Guarda el lugar después.', + 'places.refresh.apply': 'Adoptar', + 'places.refresh.replaces': 'Sustituye lo que está guardado ahora', + 'places.refresh.empty': 'vacío', + 'places.refresh.now': 'Ahora', + 'places.refresh.new': 'Nuevo', }; export default places; diff --git a/shared/src/i18n/et/places.ts b/shared/src/i18n/et/places.ts index 4143def1e..0faa47059 100644 --- a/shared/src/i18n/et/places.ts +++ b/shared/src/i18n/et/places.ts @@ -175,5 +175,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Uus pilt vajab ühendust. Salvesta uuesti, kui oled võrgus.', 'places.openPhotos': 'Näita fotosid', 'places.imageUploadError': 'Pildi üleslaadimine ebaõnnestus', + 'places.refresh.pill': 'Uued kohaandmed', + 'places.refresh.title': 'Uuenda kohaandmeid', + 'places.refresh.intro': + 'TREK teab selle koha kohta uuemaid andmeid. Vali, mida üle võtta, ülejäänu jääb samaks. Seejärel salvesta koht.', + 'places.refresh.apply': 'Võta üle', + 'places.refresh.replaces': 'Asendab praegu salvestatud väärtuse', + 'places.refresh.empty': 'tühi', + 'places.refresh.now': 'Praegu', + 'places.refresh.new': 'Uus', }; export default places; diff --git a/shared/src/i18n/fr/places.ts b/shared/src/i18n/fr/places.ts index add334165..9dccfa52f 100644 --- a/shared/src/i18n/fr/places.ts +++ b/shared/src/i18n/fr/places.ts @@ -176,5 +176,14 @@ const places: TranslationStrings = { 'Une nouvelle image a besoin d’une connexion. Enregistre à nouveau une fois en ligne.', 'places.openPhotos': 'Voir les photos', 'places.imageUploadError': "Impossible d'importer l'image", + 'places.refresh.pill': 'Nouvelles infos du lieu', + 'places.refresh.title': 'Mettre à jour les infos du lieu', + 'places.refresh.intro': + 'TREK connaît des infos plus récentes pour ce lieu. Choisissez ce que vous reprenez ; le reste ne change pas. Enregistrez ensuite le lieu.', + 'places.refresh.apply': 'Reprendre', + 'places.refresh.replaces': 'Remplace la valeur enregistrée', + 'places.refresh.empty': 'vide', + 'places.refresh.now': 'Actuel', + 'places.refresh.new': 'Nouveau', }; export default places; diff --git a/shared/src/i18n/gr/places.ts b/shared/src/i18n/gr/places.ts index 981a86c3b..f811f3a52 100644 --- a/shared/src/i18n/gr/places.ts +++ b/shared/src/i18n/gr/places.ts @@ -175,5 +175,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Μια νέα εικόνα χρειάζεται σύνδεση. Αποθήκευσε ξανά όταν είσαι online.', 'places.openPhotos': 'Προβολή φωτογραφιών', 'places.imageUploadError': 'Δεν ήταν δυνατή η μεταφόρτωση της εικόνας', + 'places.refresh.pill': 'Νέα στοιχεία τοποθεσίας', + 'places.refresh.title': 'Ενημέρωση στοιχείων τοποθεσίας', + 'places.refresh.intro': + 'Το TREK γνωρίζει νεότερα στοιχεία για αυτή την τοποθεσία. Διάλεξε τι θα υιοθετήσεις, τα υπόλοιπα μένουν ως έχουν. Μετά αποθήκευσε την τοποθεσία.', + 'places.refresh.apply': 'Υιοθέτηση', + 'places.refresh.replaces': 'Αντικαθιστά την αποθηκευμένη τιμή', + 'places.refresh.empty': 'κενό', + 'places.refresh.now': 'Τώρα', + 'places.refresh.new': 'Νέο', }; export default places; diff --git a/shared/src/i18n/hu/places.ts b/shared/src/i18n/hu/places.ts index 9de920ebc..981e95b79 100644 --- a/shared/src/i18n/hu/places.ts +++ b/shared/src/i18n/hu/places.ts @@ -174,5 +174,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Új képhez kapcsolat kell. Mentsd újra, ha online vagy.', 'places.openPhotos': 'Fotók megtekintése', 'places.imageUploadError': 'Nem sikerült feltölteni a képet', + 'places.refresh.pill': 'Új helyadatok', + 'places.refresh.title': 'Helyadatok frissítése', + 'places.refresh.intro': + 'A TREK újabb adatokat ismer erről a helyről. Válaszd ki, mit veszel át, a többi változatlan marad. Utána mentsd a helyet.', + 'places.refresh.apply': 'Átvétel', + 'places.refresh.replaces': 'Lecseréli a most mentett értéket', + 'places.refresh.empty': 'üres', + 'places.refresh.now': 'Most', + 'places.refresh.new': 'Új', }; export default places; diff --git a/shared/src/i18n/id/places.ts b/shared/src/i18n/id/places.ts index b3f259f9c..1be846bc7 100644 --- a/shared/src/i18n/id/places.ts +++ b/shared/src/i18n/id/places.ts @@ -165,5 +165,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Gambar baru butuh koneksi. Simpan lagi saat sudah online.', 'places.openPhotos': 'Lihat foto', 'places.imageUploadError': 'Tidak dapat mengunggah gambar', + 'places.refresh.pill': 'Data tempat baru', + 'places.refresh.title': 'Perbarui data tempat', + 'places.refresh.intro': + 'TREK mengetahui data yang lebih baru untuk tempat ini. Pilih yang ingin diambil; sisanya tetap. Simpan tempat setelahnya.', + 'places.refresh.apply': 'Ambil', + 'places.refresh.replaces': 'Menggantikan nilai yang tersimpan', + 'places.refresh.empty': 'kosong', + 'places.refresh.now': 'Sekarang', + 'places.refresh.new': 'Baru', }; export default places; diff --git a/shared/src/i18n/it/places.ts b/shared/src/i18n/it/places.ts index b3e7d43ce..37d6ebc84 100644 --- a/shared/src/i18n/it/places.ts +++ b/shared/src/i18n/it/places.ts @@ -174,5 +174,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Una nuova immagine richiede una connessione. Salva di nuovo quando sei online.', 'places.openPhotos': 'Mostra foto', 'places.imageUploadError': "Impossibile caricare l'immagine", + 'places.refresh.pill': 'Nuovi dati del luogo', + 'places.refresh.title': 'Aggiorna i dati del luogo', + 'places.refresh.intro': + "TREK conosce dati più recenti per questo luogo. Scegli cosa adottare; il resto resta com'è. Poi salva il luogo.", + 'places.refresh.apply': 'Adotta', + 'places.refresh.replaces': 'Sostituisce il valore salvato ora', + 'places.refresh.empty': 'vuoto', + 'places.refresh.now': 'Ora', + 'places.refresh.new': 'Nuovo', }; export default places; diff --git a/shared/src/i18n/ja/places.ts b/shared/src/i18n/ja/places.ts index f65fa30f4..7f01710aa 100644 --- a/shared/src/i18n/ja/places.ts +++ b/shared/src/i18n/ja/places.ts @@ -166,5 +166,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': '新しい画像には接続が必要です。オンラインになってからもう一度保存してください。', 'places.openPhotos': '写真を見る', 'places.imageUploadError': '画像をアップロードできませんでした', + 'places.refresh.pill': '新しい場所の情報', + 'places.refresh.title': '場所の情報を更新', + 'places.refresh.intro': + 'TREK はこの場所のより新しい情報を知っています。取り込むものを選んでください。それ以外はそのままです。その後、場所を保存してください。', + 'places.refresh.apply': '取り込む', + 'places.refresh.replaces': '現在保存されている値を置き換えます', + 'places.refresh.empty': '空', + 'places.refresh.now': '現在', + 'places.refresh.new': '新規', }; export default places; diff --git a/shared/src/i18n/ko/places.ts b/shared/src/i18n/ko/places.ts index d0e3f710b..3b700873c 100644 --- a/shared/src/i18n/ko/places.ts +++ b/shared/src/i18n/ko/places.ts @@ -164,5 +164,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': '새 이미지는 연결이 필요합니다. 온라인일 때 다시 저장하세요.', 'places.openPhotos': '사진 보기', 'places.imageUploadError': '이미지를 업로드할 수 없습니다', + 'places.refresh.pill': '새 장소 정보', + 'places.refresh.title': '장소 정보 업데이트', + 'places.refresh.intro': + 'TREK이 이 장소의 더 새로운 정보를 알고 있습니다. 가져올 항목을 고르세요. 나머지는 그대로입니다. 그다음 장소를 저장하세요.', + 'places.refresh.apply': '가져오기', + 'places.refresh.replaces': '지금 저장된 값을 대체합니다', + 'places.refresh.empty': '비어 있음', + 'places.refresh.now': '현재', + 'places.refresh.new': '새 값', }; export default places; diff --git a/shared/src/i18n/nl/places.ts b/shared/src/i18n/nl/places.ts index 1e1a0ec99..9a5c97598 100644 --- a/shared/src/i18n/nl/places.ts +++ b/shared/src/i18n/nl/places.ts @@ -175,5 +175,14 @@ const places: TranslationStrings = { 'Een nieuwe afbeelding heeft een verbinding nodig. Sla opnieuw op zodra je online bent.', 'places.openPhotos': 'Foto’s bekijken', 'places.imageUploadError': 'Afbeelding uploaden mislukt', + 'places.refresh.pill': 'Nieuwe plaatsgegevens', + 'places.refresh.title': 'Plaatsgegevens bijwerken', + 'places.refresh.intro': + 'TREK kent nieuwere gegevens voor deze plaats. Kies wat je overneemt; de rest blijft zoals het is. Sla de plaats daarna op.', + 'places.refresh.apply': 'Overnemen', + 'places.refresh.replaces': 'Vervangt wat nu is opgeslagen', + 'places.refresh.empty': 'leeg', + 'places.refresh.now': 'Nu', + 'places.refresh.new': 'Nieuw', }; export default places; diff --git a/shared/src/i18n/pl/places.ts b/shared/src/i18n/pl/places.ts index a5472423b..d49877b15 100644 --- a/shared/src/i18n/pl/places.ts +++ b/shared/src/i18n/pl/places.ts @@ -190,5 +190,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Nowy obraz wymaga połączenia. Zapisz ponownie, gdy będziesz online.', 'places.openPhotos': 'Pokaż zdjęcia', 'places.imageUploadError': 'Nie udało się przesłać zdjęcia', + 'places.refresh.pill': 'Nowe dane miejsca', + 'places.refresh.title': 'Zaktualizuj dane miejsca', + 'places.refresh.intro': + 'TREK zna nowsze dane tego miejsca. Wybierz, co przejąć, reszta pozostanie bez zmian. Potem zapisz miejsce.', + 'places.refresh.apply': 'Przejmij', + 'places.refresh.replaces': 'Zastępuje obecnie zapisaną wartość', + 'places.refresh.empty': 'puste', + 'places.refresh.now': 'Teraz', + 'places.refresh.new': 'Nowe', }; export default places; diff --git a/shared/src/i18n/ru/places.ts b/shared/src/i18n/ru/places.ts index d4755eaaa..d7292ba67 100644 --- a/shared/src/i18n/ru/places.ts +++ b/shared/src/i18n/ru/places.ts @@ -190,5 +190,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Для нового изображения нужно подключение. Сохрани ещё раз, когда будешь онлайн.', 'places.openPhotos': 'Показать фото', 'places.imageUploadError': 'Не удалось загрузить изображение', + 'places.refresh.pill': 'Новые данные места', + 'places.refresh.title': 'Обновить данные места', + 'places.refresh.intro': + 'TREK знает более свежие данные об этом месте. Выберите, что перенять, остальное останется как есть. Затем сохраните место.', + 'places.refresh.apply': 'Перенять', + 'places.refresh.replaces': 'Заменит сохранённое значение', + 'places.refresh.empty': 'пусто', + 'places.refresh.now': 'Сейчас', + 'places.refresh.new': 'Новое', }; export default places; diff --git a/shared/src/i18n/sk/places.ts b/shared/src/i18n/sk/places.ts index ec9b1cdd7..a65b8668f 100644 --- a/shared/src/i18n/sk/places.ts +++ b/shared/src/i18n/sk/places.ts @@ -183,5 +183,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Nový obrázok potrebuje pripojenie. Ulož znova, keď budeš online.', 'places.openPhotos': 'Zobraziť fotky', 'places.imageUploadError': 'Obrázok sa nepodarilo nahrať', + 'places.refresh.pill': 'Nové údaje o mieste', + 'places.refresh.title': 'Aktualizovať údaje o mieste', + 'places.refresh.intro': + 'TREK pozná novšie údaje o tomto mieste. Vyberte, čo chcete prevziať, zvyšok zostane bez zmeny. Potom miesto uložte.', + 'places.refresh.apply': 'Prevziať', + 'places.refresh.replaces': 'Nahradí aktuálne uloženú hodnotu', + 'places.refresh.empty': 'prázdne', + 'places.refresh.now': 'Teraz', + 'places.refresh.new': 'Nové', }; export default places; diff --git a/shared/src/i18n/sv/places.ts b/shared/src/i18n/sv/places.ts index 1a2bf99eb..887c1d59b 100644 --- a/shared/src/i18n/sv/places.ts +++ b/shared/src/i18n/sv/places.ts @@ -174,5 +174,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'En ny bild behöver en anslutning. Spara igen när du är online.', 'places.openPhotos': 'Visa foton', 'places.imageUploadError': 'Det gick inte att ladda upp bilden', + 'places.refresh.pill': 'Nya platsuppgifter', + 'places.refresh.title': 'Uppdatera platsuppgifter', + 'places.refresh.intro': + 'TREK känner till nyare uppgifter för den här platsen. Välj vad du vill ta över, resten förblir som det är. Spara platsen efteråt.', + 'places.refresh.apply': 'Ta över', + 'places.refresh.replaces': 'Ersätter det som är sparat nu', + 'places.refresh.empty': 'tomt', + 'places.refresh.now': 'Nu', + 'places.refresh.new': 'Nytt', }; export default places; diff --git a/shared/src/i18n/th/places.ts b/shared/src/i18n/th/places.ts index 8c214b55b..c40f10976 100644 --- a/shared/src/i18n/th/places.ts +++ b/shared/src/i18n/th/places.ts @@ -166,5 +166,14 @@ const places: TranslationStrings = { 'places.dayScoped': 'แสดงเฉพาะวันที่เปิดอยู่', 'places.dayScopedClear': 'แสดงทั้งทริป', 'places.source.amap': 'Amap', + 'places.refresh.pill': 'ข้อมูลสถานที่ใหม่', + 'places.refresh.title': 'อัปเดตข้อมูลสถานที่', + 'places.refresh.intro': + 'TREK มีข้อมูลที่ใหม่กว่าสำหรับสถานที่นี้ เลือกสิ่งที่ต้องการนำมาใช้ ส่วนที่เหลือคงเดิม จากนั้นบันทึกสถานที่', + 'places.refresh.apply': 'นำมาใช้', + 'places.refresh.replaces': 'แทนที่ค่าที่บันทึกไว้ตอนนี้', + 'places.refresh.empty': 'ว่าง', + 'places.refresh.now': 'ตอนนี้', + 'places.refresh.new': 'ใหม่', }; export default places; diff --git a/shared/src/i18n/tr/places.ts b/shared/src/i18n/tr/places.ts index 95a0526ac..259c0b8ff 100644 --- a/shared/src/i18n/tr/places.ts +++ b/shared/src/i18n/tr/places.ts @@ -176,5 +176,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Yeni bir görsel bağlantı gerektirir. Çevrimiçi olunca yeniden kaydet.', 'places.openPhotos': 'Fotoğrafları göster', 'places.imageUploadError': 'Görsel yüklenemedi', + 'places.refresh.pill': 'Yeni yer bilgileri', + 'places.refresh.title': 'Yer bilgilerini güncelle', + 'places.refresh.intro': + 'TREK bu yer için daha yeni bilgiler biliyor. Neyi alacağını seç, gerisi olduğu gibi kalır. Ardından yeri kaydet.', + 'places.refresh.apply': 'Al', + 'places.refresh.replaces': 'Şu an kayıtlı değerin yerini alır', + 'places.refresh.empty': 'boş', + 'places.refresh.now': 'Şimdi', + 'places.refresh.new': 'Yeni', }; export default places; diff --git a/shared/src/i18n/uk/places.ts b/shared/src/i18n/uk/places.ts index bac020df4..14c2bbecc 100644 --- a/shared/src/i18n/uk/places.ts +++ b/shared/src/i18n/uk/places.ts @@ -190,5 +190,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Для нового зображення потрібне з’єднання. Збережи ще раз, коли будеш онлайн.', 'places.openPhotos': 'Показати фото', 'places.imageUploadError': 'Не вдалося завантажити зображення', + 'places.refresh.pill': 'Нові дані місця', + 'places.refresh.title': 'Оновити дані місця', + 'places.refresh.intro': + 'TREK знає новіші дані про це місце. Виберіть, що перейняти, решта залишиться як є. Потім збережіть місце.', + 'places.refresh.apply': 'Перейняти', + 'places.refresh.replaces': 'Замінить збережене значення', + 'places.refresh.empty': 'порожньо', + 'places.refresh.now': 'Зараз', + 'places.refresh.new': 'Нове', }; export default places; diff --git a/shared/src/i18n/vi/places.ts b/shared/src/i18n/vi/places.ts index 4b267dd10..5eda89c28 100644 --- a/shared/src/i18n/vi/places.ts +++ b/shared/src/i18n/vi/places.ts @@ -166,5 +166,14 @@ const places: TranslationStrings = { 'places.image.needsConnection': 'Ảnh mới cần kết nối. Hãy lưu lại khi bạn trực tuyến.', 'places.openPhotos': 'Xem ảnh', 'places.imageUploadError': 'Không thể tải ảnh lên', + 'places.refresh.pill': 'Thông tin địa điểm mới', + 'places.refresh.title': 'Cập nhật thông tin địa điểm', + 'places.refresh.intro': + 'TREK biết thông tin mới hơn cho địa điểm này. Chọn những gì muốn lấy, phần còn lại giữ nguyên. Sau đó lưu địa điểm.', + 'places.refresh.apply': 'Lấy', + 'places.refresh.replaces': 'Thay thế giá trị đang lưu', + 'places.refresh.empty': 'trống', + 'places.refresh.now': 'Hiện tại', + 'places.refresh.new': 'Mới', }; export default places; diff --git a/shared/src/i18n/zh-TW/places.ts b/shared/src/i18n/zh-TW/places.ts index 56f42cbfb..daeb787f7 100644 --- a/shared/src/i18n/zh-TW/places.ts +++ b/shared/src/i18n/zh-TW/places.ts @@ -162,5 +162,13 @@ const places: TranslationStrings = { 'places.image.needsConnection': '新圖片需要連線。連線後請再儲存一次。', 'places.openPhotos': '查看照片', 'places.imageUploadError': '無法上傳圖片', + 'places.refresh.pill': '新的地點資訊', + 'places.refresh.title': '更新地點資訊', + 'places.refresh.intro': 'TREK 知道這個地點更新的資訊。選擇要採用的內容,其餘保持不變。之後儲存地點。', + 'places.refresh.apply': '採用', + 'places.refresh.replaces': '取代目前儲存的值', + 'places.refresh.empty': '空', + 'places.refresh.now': '目前', + 'places.refresh.new': '新', }; export default places; diff --git a/shared/src/i18n/zh/places.ts b/shared/src/i18n/zh/places.ts index f461a555b..8950ee73c 100644 --- a/shared/src/i18n/zh/places.ts +++ b/shared/src/i18n/zh/places.ts @@ -162,5 +162,13 @@ const places: TranslationStrings = { 'places.image.needsConnection': '新图片需要联网。联网后请再次保存。', 'places.openPhotos': '查看照片', 'places.imageUploadError': '无法上传图片', + 'places.refresh.pill': '新的地点信息', + 'places.refresh.title': '更新地点信息', + 'places.refresh.intro': 'TREK 知道这个地点更新的信息。选择要采用的内容,其余保持不变。之后保存地点。', + 'places.refresh.apply': '采用', + 'places.refresh.replaces': '替换当前保存的值', + 'places.refresh.empty': '空', + 'places.refresh.now': '当前', + 'places.refresh.new': '新', }; export default places; diff --git a/wiki/Places-and-Search.md b/wiki/Places-and-Search.md index d09795b6d..808d52b7f 100644 --- a/wiki/Places-and-Search.md +++ b/wiki/Places-and-Search.md @@ -94,6 +94,10 @@ The hours stay folded away until you click **Add opening hours**. Each weekday t The place inspector shows the phone and the e-mail address as pills in its head band (a click calls or writes), and your own hours win over the ones a provider knows. +### Newer place details + +When you edit a saved place, TREK looks the place up again. If the lookup knows a website, phone number, e-mail address or opening hours that differ from what the place holds, a **New place details** pill with the number of differences appears in the head of the form. It opens a list with what the place holds now beside what the lookup has. A field that is empty is ticked; a field that already has a value is not, and says that it would replace it. **Take over** writes only the ticked fields into the form, and the place keeps them once you save it. A field the lookup knows nothing about is never offered, so refreshing never empties anything. + ### Costs for a place With the [Costs](Budget-Tracking) addon enabled, the place form carries the same **Costs** block that bookings and transports have. **Create expense** saves the place and then opens the Costs editor for a new expense linked to it: the museum ticket, the guided tour, the entry fee. On a saved place, **Link existing expense** ties one that is already in Costs. Every linked expense is listed with edit, **Unlink, keep the expense** and **Remove expense**, and a place can carry several.