mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
feat(places): notes, visits, tours, history, tags and location in the place sheet, saved lists on the trip map
Both the desktop sheet and the phone sheet of All places show the place's location as a badge, its notes per list, its visits from trips (hidden without any), linked tours and bookings, its change history and the reader's own tags with a tag filter. A trip map can show the places of linked lists and add one to the trip. All places reloads after a list is added or removed.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import type { PlaceActivity, PlaceActivityCandidate, PlaceHistoryEntry } from '@trek/shared';
|
||||
|
||||
import type { TranslationFn } from '../../types';
|
||||
import { dayDate } from './libraryDates';
|
||||
|
||||
/** The words for one changed detail: which detail, and the old and the new value as the reader reads them. */
|
||||
export function historyLine(
|
||||
entry: PlaceHistoryEntry,
|
||||
t: TranslationFn
|
||||
): { field: string; from: string | null; to: string | null } {
|
||||
const field = t(`placeHistory.field.${entry.field}`);
|
||||
// A picture or the opening hours say nothing as text: only that they changed.
|
||||
if (entry.field === 'image' || entry.field === 'opening_hours') return { field, from: null, to: null };
|
||||
if (entry.field === 'status') {
|
||||
const word = (v: string | null) => (v ? t(`collections.status.${v}`) : null);
|
||||
return { field, from: word(entry.old_value), to: word(entry.new_value) };
|
||||
}
|
||||
return { field, from: entry.old_value, to: entry.new_value };
|
||||
}
|
||||
|
||||
/** Who changed it: the person, TREK itself, or someone whose account is gone. */
|
||||
export function historyEditor(entry: PlaceHistoryEntry, t: TranslationFn): string {
|
||||
if (entry.automatic) return t('placeHistory.automatic');
|
||||
return entry.editor?.username ?? t('placeHistory.formerMember');
|
||||
}
|
||||
|
||||
/** When it changed, as a short date and time in the reader's language. */
|
||||
export function historyWhen(entry: PlaceHistoryEntry, language: string): string {
|
||||
if (!entry.changed_at) return '';
|
||||
const d = new Date(`${entry.changed_at.replace(' ', 'T')}${entry.changed_at.endsWith('Z') ? '' : 'Z'}`);
|
||||
if (Number.isNaN(d.getTime())) return '';
|
||||
return new Intl.DateTimeFormat(language, {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(d);
|
||||
}
|
||||
|
||||
/** The second line of a tour or booking: where it lives and when it is. */
|
||||
export function activityLine(
|
||||
activity: PlaceActivity | PlaceActivityCandidate,
|
||||
language: string,
|
||||
t: TranslationFn
|
||||
): string {
|
||||
const where = activity.origin.kind === 'trip' ? activity.origin.trip_title : activity.origin.collection_name;
|
||||
const day = activity.date ? dayDate(activity.date, language) : null;
|
||||
const when = day ?? (activity.day_number != null ? t('collections.library.day', { day: activity.day_number }) : null);
|
||||
const kind = activity.type === 'booking' ? t('placeActivities.booking') : t('placeActivities.tour');
|
||||
return [kind, where, when].filter(Boolean).join(', ');
|
||||
}
|
||||
|
||||
/** The line under a change: where, who and when, leaving out what is not known. */
|
||||
export function historyMeta(entry: PlaceHistoryEntry, t: TranslationFn, language: string): string {
|
||||
const where = entry.origin.kind === 'trip' ? entry.origin.trip_title : entry.origin.collection_name;
|
||||
return [where, historyEditor(entry, t), historyWhen(entry, language)].filter(Boolean).join(', ');
|
||||
}
|
||||
Reference in New Issue
Block a user