This commit is contained in:
Daniel Flanagan 2022-10-11 16:17:21 -05:00
parent 56378fbc26
commit e2ed9be08f
Signed by untrusted user: lytedev-divvy
GPG Key ID: 6D69CEEE4ABBCD82
4 changed files with 50 additions and 9 deletions

View File

@ -1,11 +1,47 @@
import { JSX } from "preact";
import { type PublicUser } from "@/types.ts";
const NAV_ITEM_CLASSES =
"flex justify-center items-center px-4 py-2 hover:bg-gray-300 dark:hover:bg-gray-700";
const HEADER_CLASSES = "bg-gray-200 dark:bg-gray-800";
export function Page(props: JSX.HTMLAttributes<HTMLDivElement>) {
export function LoginNavItems() {
return (
<>
<a
tabIndex={12}
href="/register"
class={`${NAV_ITEM_CLASSES} ml-auto`}
>
Register
</a>
<a tabIndex={13} href="/login" class={NAV_ITEM_CLASSES}>Login</a>
</>
);
}
export function UserNavItems() {
return (
<>
<a
tabIndex={12}
href="/profile"
class={`${NAV_ITEM_CLASSES} ml-auto`}
>
Profile
</a>
<a tabIndex={13} href="/dashboard" class={NAV_ITEM_CLASSES}>Dashboard</a>
<a tabIndex={13} href="/logout" class={NAV_ITEM_CLASSES}>Logout</a>
</>
);
}
export interface PageProps extends JSX.HTMLAttributes<HTMLDivElement> {
user?: PublicUser;
}
export function Page(props: PageProps) {
return (
<div class="relative min-h-screen flex flex-col">
<header class="flex justify-start items-center">
@ -18,10 +54,7 @@ export function Page(props: JSX.HTMLAttributes<HTMLDivElement>) {
<h1 class="text-2xl">LyricScreen</h1>
</a>
<a tabIndex={11} href="/note" class={NAV_ITEM_CLASSES}>Notes</a>
<a tabIndex={12} href="/register" class={NAV_ITEM_CLASSES}>
Register
</a>
<a tabIndex={13} href="/login" class={NAV_ITEM_CLASSES}>Login</a>
{props.user ? UserNavItems() : LoginNavItems()}
</nav>
</header>
<main class="p-2">

3
log.ts
View File

@ -1,6 +1,7 @@
export * as log from "$std/log/mod.ts";
import * as log from "$std/log/mod.ts";
export * as log from "$std/log/mod.ts";
const levelColors = {};
export function setupLoggers() {

View File

@ -1,13 +1,13 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { Page } from "@/components/Page.tsx";
// import { getToken, getUser } from "@/db/mod.ts";
// import * as base64 from "$std/encoding/base64.ts";
import { Handlers, PageProps } from "$fresh/server.ts";
import { type ContextState } from "@/types.ts";
export const handler: Handlers<unknown, ContextState> = {
async GET(_request: Request, context) {
const user: Partial<ContextState["user"]> = context.state.user;
delete user.passwordDigest;
if (user && "passwordDigest" in user) delete user.passwordDigest;
return await context.render(context.state.user);
},
};

View File

@ -22,6 +22,13 @@ export interface User extends Identifiable, Timestamped {
displayName?: string;
}
export type PublicUser = Pick<
User,
| "displayName"
| "username"
| keyof Identifiable
>;
export interface Note extends Identifiable, Timestamped {
content: string;
userId: User["id"] | null;
@ -42,5 +49,5 @@ export interface Token extends Created {
export type TokenDigest = string;
export interface ContextState {
user?: Omit<User, "passwordDigest" | keyof Timestamped> & Partial<User>;
user?: PublicUser;
}