Files
bewcloud/routes/dashboard.tsx
Bruno Bernardino 6cfb62d1a2 Refactor data handlers + misc fixes
This refactors the data handlers into a more standard/understood model-like architecture, to prepare for a new, more robust config system.

It also fixes a problem with creating new Notes and uploading new Photos via the web interface (related to #58).

Finally, it speeds up docker builds by sending in less files, which aren't necessary or will be built anyway.

This is all in preparation to allow building #13 more robustly.
2025-05-24 08:24:10 +01:00

39 lines
1.1 KiB
TypeScript

import { Handlers, PageProps } from 'fresh/server.ts';
import { Dashboard, FreshContextState } from '/lib/types.ts';
import { DashboardModel } from '/lib/models/dashboard.ts';
import Notes from '/islands/dashboard/Notes.tsx';
import Links from '/islands/dashboard/Links.tsx';
interface Data {
userDashboard: Dashboard;
}
export const handler: Handlers<Data, FreshContextState> = {
async GET(request, context) {
if (!context.state.user) {
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
}
let userDashboard = await DashboardModel.getByUserId(context.state.user.id);
if (!userDashboard) {
userDashboard = await DashboardModel.create(context.state.user.id);
}
return await context.render({ userDashboard });
},
};
export default function DashboardPage({ data }: PageProps<Data, FreshContextState>) {
const initialNotes = data?.userDashboard?.data?.notes || 'Jot down some notes here.';
return (
<main>
<Links initialLinks={data?.userDashboard?.data?.links || []} />
<Notes initialNotes={initialNotes} />
</main>
);
}