mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
This implements a huge change, where Fresh is removed as a framework and serving files, allowing more control over importing, bundling, and serving files and components. The biggest challenge was to continue making sure that there weren't too many places to look into for import versions, and `PasswordlessPasskeyLogin.tsx` became a prototype in migrating a component to fully SSR, no need for frontend parsing (via Babel) or bundling (via a custom-script, downloading frontend dependencies from esm.sh). Still, there are too many components to migrate like that, and it's all working, so I likely won't even attempt it unless there's some bug, new feature, or security vulnerability to address that warrants a rewrite of those. This also updates all dependencies (except `@libs/xml` because that still causes some breaking in DAV endpoints), including Deno! All other advantages can be seen in the related issues, and the breaking change this (v4.0.0) introduces is related simply to `config.email.tlsMode` (which had a deprecation warning throughout v3), and because, while I tested many things exhaustively, it's not impossible something broke that I didn't see. Closes #141 Closes #132
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import page, { RequestHandlerParams } from '/lib/page.ts';
|
|
|
|
import { Dashboard } from '/lib/types.ts';
|
|
import { DashboardModel } from '/lib/models/dashboard.ts';
|
|
import { AppConfig } from '/lib/config.ts';
|
|
import { html } from '/public/ts/utils/misc.ts';
|
|
import { basicLayoutResponse } from '/lib/utils/layout.tsx';
|
|
import Loading from '/components/Loading.ts';
|
|
|
|
const titlePrefix = 'Dashboard';
|
|
|
|
async function get({ request, match, user, session, isRunningLocally }: RequestHandlerParams) {
|
|
if (!(await AppConfig.isAppEnabled('dashboard'))) {
|
|
return new Response('Redirect', { status: 303, headers: { 'Location': `/` } });
|
|
}
|
|
|
|
let userDashboard = await DashboardModel.getByUserId(user!.id);
|
|
|
|
if (!userDashboard) {
|
|
userDashboard = await DashboardModel.create(user!.id);
|
|
}
|
|
|
|
const htmlContent = defaultHtmlContent({ userDashboard });
|
|
|
|
return basicLayoutResponse(htmlContent, {
|
|
currentPath: match.pathname.input,
|
|
titlePrefix,
|
|
match,
|
|
request,
|
|
user,
|
|
session,
|
|
isRunningLocally,
|
|
});
|
|
}
|
|
|
|
function defaultHtmlContent({ userDashboard }: { userDashboard: Dashboard }) {
|
|
const initialNotes = userDashboard?.data?.notes || 'Jot down some notes here.';
|
|
|
|
return html`
|
|
<main id="main">
|
|
${Loading()}
|
|
<section id="links"></section>
|
|
<section id="notes"></section>
|
|
</main>
|
|
|
|
<script type="module">
|
|
import { h, render, Fragment } from 'preact';
|
|
|
|
// Imported files need some preact globals to work
|
|
window.h = h;
|
|
window.Fragment = Fragment;
|
|
|
|
import Links from '/public/components/dashboard/Links.js';
|
|
import Notes from '/public/components/dashboard/Notes.js';
|
|
|
|
const linksElement = document.getElementById('links');
|
|
const notesElement = document.getElementById('notes');
|
|
|
|
if (linksElement) {
|
|
const linksApp = h(Links, { initialLinks: ${JSON.stringify(userDashboard?.data?.links || [])} });
|
|
|
|
render(linksApp, linksElement);
|
|
}
|
|
|
|
if (notesElement) {
|
|
const notesApp = h(Notes, { initialNotes: ${JSON.stringify(initialNotes)} });
|
|
|
|
render(notesApp, notesElement);
|
|
}
|
|
|
|
if (linksElement && notesElement) {
|
|
document.getElementById('loading')?.remove();
|
|
}
|
|
</script>
|
|
`;
|
|
}
|
|
|
|
export default page({
|
|
get,
|
|
accessMode: 'user',
|
|
});
|