mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
47 lines
2.4 KiB
TypeScript
47 lines
2.4 KiB
TypeScript
// Pure formatting helper for note timestamps. Falls back to translated
|
|
// relative labels for recent timestamps and a localized short date beyond a week.
|
|
export const formatTimestamp = (ts, t, locale) => {
|
|
if (!ts) return ''
|
|
const d = new Date(ts.endsWith?.('Z') ? ts : ts + 'Z')
|
|
const now = new Date()
|
|
const diffMs = now.getTime() - d.getTime()
|
|
const diffMins = Math.floor(diffMs / 60000)
|
|
if (diffMins < 1) return t('collab.chat.justNow') || 'just now'
|
|
if (diffMins < 60) return t('collab.chat.minutesAgo', { n: diffMins }) || `${diffMins}m ago`
|
|
const diffHrs = Math.floor(diffMins / 60)
|
|
if (diffHrs < 24) return t('collab.chat.hoursAgo', { n: diffHrs }) || `${diffHrs}h ago`
|
|
const diffDays = Math.floor(diffHrs / 24)
|
|
if (diffDays < 7) return t('collab.notes.daysAgo', { n: diffDays }) || `${diffDays}d ago`
|
|
return d.toLocaleDateString(locale || undefined, { month: 'short', day: 'numeric' })
|
|
}
|
|
|
|
/** The name a category had before this Save: a rename maps old -> new, so look the new name up. */
|
|
export const originalCategoryName = (cat: string, renames: Record<string, string>): string =>
|
|
Object.entries(renames).find(([, to]) => to === cat)?.[0] ?? cat
|
|
|
|
/**
|
|
* What saving the category dialog writes. A colour goes onto the notes of a category
|
|
* that has some, looked up under the name they still carry (renames are applied to the
|
|
* notes separately, and `notes` is the list from before them), so renaming and
|
|
* recolouring in one Save keeps both. A category without notes is kept as an empty one.
|
|
*/
|
|
export function planCategoryColorSave(
|
|
notes: ReadonlyArray<{ id: number; category?: string | null }>,
|
|
currentColors: Record<string, string>,
|
|
nextColors: Record<string, string>,
|
|
renames: Record<string, string> = {},
|
|
): { updates: { noteId: number; color: string }[]; emptyCategories: Record<string, string> } {
|
|
const updates: { noteId: number; color: string }[] = []
|
|
const emptyCategories: Record<string, string> = {}
|
|
for (const [cat, color] of Object.entries(nextColors)) {
|
|
const original = originalCategoryName(cat, renames)
|
|
const inCat = notes.filter(n => n.category === original || n.category === cat)
|
|
if (inCat.length === 0) {
|
|
emptyCategories[cat] = color
|
|
} else if ((currentColors[original] ?? currentColors[cat]) !== color) {
|
|
for (const n of inCat) updates.push({ noteId: n.id, color })
|
|
}
|
|
}
|
|
return { updates, emptyCategories }
|
|
}
|