Enable users to see all their saved events on the home screen, sorted by date with upcoming events first. Key capabilities: - EventCard with title, relative time display, and organizer/attendee role badge - Sortable EventList with past-event visual distinction (faded style) - Empty state when no events are stored - Swipe-to-delete gesture with confirmation dialog - Floating action button for quick event creation - Rename router param :token → :eventToken across all views - useRelativeTime composable (Intl.RelativeTimeFormat) - useEventStorage: add validation, removeEvent(), reactive versioning - Full E2E and unit test coverage for all new components Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
24 lines
787 B
TypeScript
24 lines
787 B
TypeScript
const UNITS: [Intl.RelativeTimeFormatUnit, number][] = [
|
|
['year', 365 * 24 * 60 * 60],
|
|
['month', 30 * 24 * 60 * 60],
|
|
['week', 7 * 24 * 60 * 60],
|
|
['day', 24 * 60 * 60],
|
|
['hour', 60 * 60],
|
|
['minute', 60],
|
|
['second', 1],
|
|
]
|
|
|
|
export function formatRelativeTime(dateTime: string, now: Date = new Date()): string {
|
|
const target = new Date(dateTime)
|
|
const diffSeconds = Math.round((target.getTime() - now.getTime()) / 1000)
|
|
|
|
for (const [unit, secondsInUnit] of UNITS) {
|
|
if (Math.abs(diffSeconds) >= secondsInUnit) {
|
|
const value = Math.round(diffSeconds / secondsInUnit)
|
|
return new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' }).format(value, unit)
|
|
}
|
|
}
|
|
|
|
return new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' }).format(0, 'second')
|
|
}
|