Files
Calendar_Frontend/lib/events.ts
PaddyandClaude Opus 5.5 0cda40f85e Rewrite the calendar frontend in Next.js
Replaces the Angular 18 app with Next.js 16 / React 19 / Tailwind 4 / shadcn,
the same stack and design system as nachklang-feedback, planned in
docs/rewrite-plan.md.

- Admin: all calendars in one mobile-friendly list (month groups, calendar
  chips, Kommend/Vergangen/Alle, search, sort, filters in the URL), an edit
  sheet for create/edit/duplicate/delete, publish confirmation, and an
  "Abonnieren" dialog with subscription links for every calendar.
- Public landing page: subscribe links from env instead of hardcoded, plus
  the next public events, server-rendered and revalidated every 5 minutes.
- All times handled explicitly as Europe/Berlin; whole-day events stored as
  00:00-23:59. Fixes carried over from the Angular app: the move dialog
  leaking a cancelled calendar change, saves that looked saved when they
  failed, in-place Date mutation, and duplicated calendar-id mappings.
- Same shared-session auth as before (proxy.ts gate, /admin/me, 401 vs 403).
- 112 Vitest tests over lib/; docs in docs/ (architecture, features,
  gotchas, API wish list, deployment).

Needs the API branch feature/calendar-ical-escaping-subscriptions deployed
first (GET /calendar/events/subscriptions).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:15:59 +02:00

63 lines
2.1 KiB
TypeScript

import type { ApiEvent, CalendarEvent, EventStatus } from "@/lib/types";
const STATUSES: readonly EventStatus[] = ["PUBLIC", "PRIVATE", "DRAFT", "DELETED"];
const parseDate = (value: string | null | undefined): Date | null => {
if (!value) {
return null;
}
const date = new Date(value);
return Number.isNaN(date.getTime()) ? null : date;
};
/**
* Turns one row of the API's JSON into a `CalendarEvent`, or null for a row
* the list should not show.
*
* Null covers deleted events - the admin feed returns them, because deleting
* only appends a version with `status = 'DELETED'` - and anything without a
* usable start and end, which a deleted row also is (all its other columns are
* null). The Angular app filtered on status alone and would have rendered such
* a row as "Invalid Date".
*
* A missing status (the anonymous public listing omits it) means PUBLIC, since
* that listing only returns published events. An unknown one is treated as
* PRIVATE (and saved back as such) - "not public" is the safe reading; it is
* never silently promoted to PUBLIC.
*/
export const parseApiEvent = (row: ApiEvent): CalendarEvent | null => {
const status: EventStatus =
row.status == null ? "PUBLIC" : STATUSES.includes(row.status as EventStatus) ? (row.status as EventStatus) : "PRIVATE";
if (status === "DELETED") {
return null;
}
const start = parseDate(row.startDateTime);
const end = parseDate(row.endDateTime);
if (!start || !end) {
return null;
}
return {
eventId: row.eventId,
calendarId: row.calendarId,
uuid: row.uuid ?? "",
name: row.name ?? "",
description: row.description ?? "",
start,
end,
created: parseDate(row.createdDate),
lastModified: parseDate(row.lastModifiedDate),
location: row.location ?? "",
createdBy: row.createdBy ?? "",
lastModifiedBy: row.lastModifiedBy ?? "",
url: row.url ?? "",
wholeDay: Boolean(row.wholeDay),
repeatFrequency: row.repeatFrequency ?? "",
status,
};
};
export const parseApiEvents = (rows: ApiEvent[]): CalendarEvent[] =>
rows.map(parseApiEvent).filter((e): e is CalendarEvent => e !== null);