Calendar SQL and CRUD

This commit is contained in:
Bruno Bernardino
2024-03-19 16:05:47 +00:00
parent 062c0d3d09
commit eff6a08771
16 changed files with 703 additions and 219 deletions

29
routes/calendars.tsx Normal file
View File

@@ -0,0 +1,29 @@
import { Handlers, PageProps } from 'fresh/server.ts';
import { Calendar, FreshContextState } from '/lib/types.ts';
import { getCalendars } from '/lib/data/calendar.ts';
import Calendars from '/islands/calendar/Calendars.tsx';
interface Data {
userCalendars: Calendar[];
}
export const handler: Handlers<Data, FreshContextState> = {
async GET(request, context) {
if (!context.state.user) {
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
}
const userCalendars = await getCalendars(context.state.user.id);
return await context.render({ userCalendars });
},
};
export default function CalendarsPage({ data }: PageProps<Data, FreshContextState>) {
return (
<main>
<Calendars initialCalendars={data.userCalendars || []} />
</main>
);
}