diff --git a/mod.ts b/mod.ts index a7ab00d..628767b 100644 --- a/mod.ts +++ b/mod.ts @@ -43,13 +43,13 @@ Deno.serve({ port: config.api.port }, async (req) => { } else if (path.startsWith('/home/')) { // SSR "home page" const userId = path.replace('/home/', ''); - const userMatch = await dbClient.query('SELECT id FROM users WHERE id = ?', [userId]).catch(() => { + const userMatch = await dbClient.query('SELECT name FROM users WHERE id = ?', [userId]).catch(() => { failed = true; }); if (failed) return buildPage("Couldn't read DB. Please try again."); if (!userMatch.length) return buildPage('User ID does not exist. Please click on the page header to go back to the sign in page.'); - return buildPage(buildHome(userId)); + return buildPage(await buildHome(userId, userMatch[0].name)); } else if (path.startsWith('/read/')) { const planId = path.replace('/read/', ''); diff --git a/ssr/buildHome.ts b/ssr/buildHome.ts index a0850be..67aebee 100644 --- a/ssr/buildHome.ts +++ b/ssr/buildHome.ts @@ -1,3 +1,44 @@ -export default (userId: string) => { - return `${userId}`; +import dbClient from 'db/client.ts'; + +interface Plan { + id: string; + name: string; + folder: string; +} + +const makePlanButtons = (planId: string, deleted: boolean) => + deleted + ? `` + : ``; + +const makePlanItem = (plan: Plan, deleted: boolean) => `