feat: migrate to Next.js for Mini App and enhance project structure
- Replaced the previous webapp with a new Mini App built using Next.js, improving performance and maintainability. - Updated the `.gitignore` to exclude Next.js build artifacts and node modules. - Revised documentation in `AGENTS.md`, `README.md`, and `architecture.md` to reflect the new Mini App structure and technology stack. - Enhanced Dockerfile to support the new build process for the Next.js application. - Updated CI workflow to build and test the Next.js application. - Added new configuration options for the Mini App, including `MINI_APP_SHORT_NAME` for improved deep linking. - Refactored frontend testing setup to accommodate the new structure and testing framework. - Removed legacy webapp files and dependencies to streamline the project.
This commit is contained in:
50
webapp-next/src/lib/calendar-data.ts
Normal file
50
webapp-next/src/lib/calendar-data.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Pure functions: group duties and calendar events by local date (YYYY-MM-DD).
|
||||
* Ported from webapp/js/calendar.js (dutiesByDate, calendarEventsByDate).
|
||||
*/
|
||||
|
||||
import type { CalendarEvent, DutyWithUser } from "@/types";
|
||||
import { localDateString } from "./date-utils";
|
||||
|
||||
/** Max days to iterate per duty; prevents infinite loop on corrupted API data (end_at < start_at). */
|
||||
const MAX_DAYS_PER_DUTY = 366;
|
||||
|
||||
/**
|
||||
* Build { localDateKey -> array of summary strings }. API date is UTC YYYY-MM-DD; map to local.
|
||||
*/
|
||||
export function calendarEventsByDate(
|
||||
events: CalendarEvent[] | null | undefined
|
||||
): Record<string, string[]> {
|
||||
const byDate: Record<string, string[]> = {};
|
||||
(events ?? []).forEach((e) => {
|
||||
const utcMidnight = new Date(e.date + "T00:00:00Z");
|
||||
const key = localDateString(utcMidnight);
|
||||
if (!byDate[key]) byDate[key] = [];
|
||||
if (e.summary) byDate[key].push(e.summary);
|
||||
});
|
||||
return byDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group duties by local date (start_at/end_at are UTC).
|
||||
*/
|
||||
export function dutiesByDate(duties: DutyWithUser[]): Record<string, DutyWithUser[]> {
|
||||
const byDate: Record<string, DutyWithUser[]> = {};
|
||||
duties.forEach((d) => {
|
||||
const start = new Date(d.start_at);
|
||||
const end = new Date(d.end_at);
|
||||
if (end < start) return;
|
||||
const endLocal = localDateString(end);
|
||||
let cursor = new Date(start);
|
||||
let iterations = 0;
|
||||
while (iterations <= MAX_DAYS_PER_DUTY) {
|
||||
const key = localDateString(cursor);
|
||||
if (!byDate[key]) byDate[key] = [];
|
||||
byDate[key].push(d);
|
||||
if (key === endLocal) break;
|
||||
cursor.setDate(cursor.getDate() + 1);
|
||||
iterations++;
|
||||
}
|
||||
});
|
||||
return byDate;
|
||||
}
|
||||
Reference in New Issue
Block a user