build out home page, need to link things up tho

This commit is contained in:
Ean Milligan
2026-04-10 15:11:32 -04:00
parent 6a02684a2a
commit 1cabb376d9
3 changed files with 48 additions and 4 deletions

4
mod.ts
View File

@@ -43,13 +43,13 @@ Deno.serve({ port: config.api.port }, async (req) => {
} else if (path.startsWith('/home/')) { } else if (path.startsWith('/home/')) {
// SSR "home page" // SSR "home page"
const userId = path.replace('/home/', ''); 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; failed = true;
}); });
if (failed) return buildPage("Couldn't read DB. Please try again."); 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.'); 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/')) { } else if (path.startsWith('/read/')) {
const planId = path.replace('/read/', ''); const planId = path.replace('/read/', '');

View File

@@ -1,3 +1,44 @@
export default (userId: string) => { import dbClient from 'db/client.ts';
return `${userId}`;
interface Plan {
id: string;
name: string;
folder: string;
}
const makePlanButtons = (planId: string, deleted: boolean) =>
deleted
? `<button>restore</button><button>perm delete</button>`
: `<button>open</button><button>share</button><button>rename</button><button>move</button><button>delete</button>`;
const makePlanItem = (plan: Plan, deleted: boolean) => `<li>${plan.folder}${plan.folder && '/'}${plan.name} - ${makePlanButtons(plan.id, deleted)}</li>`;
export default async (userId: string, userName: string) => {
let failed = false;
const plans: Plan[] = await dbClient
.query('SELECT id, name, folder FROM plans WHERE ownerId = ? AND deleted = 0 GROUP BY folder,name,id ORDER BY folder,name DESC', [userId])
.catch((e) => {
console.error(e);
failed = true;
});
if (failed) return "Couldn't read DB.";
const deletedPlans: Plan[] = await dbClient
.query('SELECT id, name, folder FROM plans WHERE ownerId = ? AND deleted = 1 GROUP BY folder,name,id ORDER BY folder,name DESC', [userId])
.catch(() => {
failed = true;
});
if (failed) return "Couldn't read DB.";
return `<div>
<h3>${userName}'s Plans:</h3>
<ul>
${plans.map((plan) => makePlanItem(plan, false)).join('')}
</ul>
<h3>${userName}'s Deleted Plans:</h3>
<ul>
${deletedPlans.map((plan) => makePlanItem(plan, true)).join('')}
</ul>
</div>`;
}; };

View File

@@ -20,6 +20,9 @@ a {
text-decoration:none; text-decoration:none;
color:white; color:white;
} }
li {
margin:0.5rem 0;
}
</style> </style>
</head> </head>
<body> <body>