Stuff?
This commit is contained in:
parent
56378fbc26
commit
e2ed9be08f
|
@ -1,11 +1,47 @@
|
||||||
import { JSX } from "preact";
|
import { JSX } from "preact";
|
||||||
|
import { type PublicUser } from "@/types.ts";
|
||||||
|
|
||||||
const NAV_ITEM_CLASSES =
|
const NAV_ITEM_CLASSES =
|
||||||
"flex justify-center items-center px-4 py-2 hover:bg-gray-300 dark:hover:bg-gray-700";
|
"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";
|
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 (
|
return (
|
||||||
<div class="relative min-h-screen flex flex-col">
|
<div class="relative min-h-screen flex flex-col">
|
||||||
<header class="flex justify-start items-center">
|
<header class="flex justify-start items-center">
|
||||||
|
@ -18,10 +54,7 @@ export function Page(props: JSX.HTMLAttributes<HTMLDivElement>) {
|
||||||
<h1 class="text-2xl">LyricScreen</h1>
|
<h1 class="text-2xl">LyricScreen</h1>
|
||||||
</a>
|
</a>
|
||||||
<a tabIndex={11} href="/note" class={NAV_ITEM_CLASSES}>Notes</a>
|
<a tabIndex={11} href="/note" class={NAV_ITEM_CLASSES}>Notes</a>
|
||||||
<a tabIndex={12} href="/register" class={NAV_ITEM_CLASSES}>
|
{props.user ? UserNavItems() : LoginNavItems()}
|
||||||
Register
|
|
||||||
</a>
|
|
||||||
<a tabIndex={13} href="/login" class={NAV_ITEM_CLASSES}>Login</a>
|
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
<main class="p-2">
|
<main class="p-2">
|
||||||
|
|
3
log.ts
3
log.ts
|
@ -1,6 +1,7 @@
|
||||||
export * as log from "$std/log/mod.ts";
|
|
||||||
import * 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 = {};
|
const levelColors = {};
|
||||||
|
|
||||||
export function setupLoggers() {
|
export function setupLoggers() {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
|
||||||
import { Page } from "@/components/Page.tsx";
|
import { Page } from "@/components/Page.tsx";
|
||||||
// import { getToken, getUser } from "@/db/mod.ts";
|
// import { getToken, getUser } from "@/db/mod.ts";
|
||||||
// import * as base64 from "$std/encoding/base64.ts";
|
// import * as base64 from "$std/encoding/base64.ts";
|
||||||
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||||
import { type ContextState } from "@/types.ts";
|
import { type ContextState } from "@/types.ts";
|
||||||
|
|
||||||
export const handler: Handlers<unknown, ContextState> = {
|
export const handler: Handlers<unknown, ContextState> = {
|
||||||
async GET(_request: Request, context) {
|
async GET(_request: Request, context) {
|
||||||
const user: Partial<ContextState["user"]> = context.state.user;
|
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);
|
return await context.render(context.state.user);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
9
types.ts
9
types.ts
|
@ -22,6 +22,13 @@ export interface User extends Identifiable, Timestamped {
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PublicUser = Pick<
|
||||||
|
User,
|
||||||
|
| "displayName"
|
||||||
|
| "username"
|
||||||
|
| keyof Identifiable
|
||||||
|
>;
|
||||||
|
|
||||||
export interface Note extends Identifiable, Timestamped {
|
export interface Note extends Identifiable, Timestamped {
|
||||||
content: string;
|
content: string;
|
||||||
userId: User["id"] | null;
|
userId: User["id"] | null;
|
||||||
|
@ -42,5 +49,5 @@ export interface Token extends Created {
|
||||||
export type TokenDigest = string;
|
export type TokenDigest = string;
|
||||||
|
|
||||||
export interface ContextState {
|
export interface ContextState {
|
||||||
user?: Omit<User, "passwordDigest" | keyof Timestamped> & Partial<User>;
|
user?: PublicUser;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue