mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
d758f4c592
The desktop dialog and the phone sheet of a place show its overview, notes, tours and bookings, photos and files and its history in tabs, with the tags of each list and trip, a markdown notes editor, uploads and the place picture. The rating bar of All places is the rating row the lists show, with its voters, and votes once for every copy. All places filters by a lowest rating and sorts by it, and the edit form changes the first copy the reader may edit, which the server carries to the others.
58 lines
2.6 KiB
TypeScript
58 lines
2.6 KiB
TypeScript
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(', ');
|
|
}
|
|
|
|
/** A position as the location badge shows it, five decimals, about a metre. */
|
|
export function coordsText(lat: number, lng: number): string {
|
|
return `${lat.toFixed(5)}, ${lng.toFixed(5)}`;
|
|
}
|