33 lines
964 B
TypeScript
33 lines
964 B
TypeScript
import { dateKey, parseDateKey } from "./agenda-date.ts"
|
|
|
|
export type AgendaView = "day" | "week" | "month"
|
|
|
|
export const AGENDA_VIEWS: AgendaView[] = ["day", "week", "month"]
|
|
|
|
export const AGENDA_VIEW_LABELS: Record<AgendaView, string> = {
|
|
day: "Jour",
|
|
week: "Semaine",
|
|
month: "Mois",
|
|
}
|
|
|
|
export interface AgendaRoute {
|
|
view: AgendaView | null
|
|
date: Date
|
|
}
|
|
|
|
function isAgendaView(value: string): value is AgendaView {
|
|
return (AGENDA_VIEWS as string[]).includes(value)
|
|
}
|
|
|
|
/** `/agenda[/{view}[/{yyyy-MM-dd}]]` — view null = laisser le choix au client. */
|
|
export function parseAgendaSegments(segments?: string[]): AgendaRoute {
|
|
const [rawView, rawDate] = segments ?? []
|
|
const view = rawView && isAgendaView(rawView) ? rawView : null
|
|
const date = (rawDate ? parseDateKey(rawDate) : null) ?? new Date()
|
|
return { view, date }
|
|
}
|
|
|
|
export function buildAgendaPath(view: AgendaView, date: Date): string {
|
|
return `/agenda/${view}/${dateKey(date)}`
|
|
}
|