WIP _app.tsx for "global" state
This commit is contained in:
parent
e2ed9be08f
commit
34b440213f
6 changed files with 69 additions and 38 deletions
|
@ -42,6 +42,7 @@ export interface PageProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|||
}
|
||||
|
||||
export function Page(props: PageProps) {
|
||||
console.log("PageProps:", props);
|
||||
return (
|
||||
<div class="relative min-h-screen flex flex-col">
|
||||
<header class="flex justify-start items-center">
|
||||
|
|
70
fresh.gen.ts
70
fresh.gen.ts
|
@ -6,23 +6,24 @@ import config from "./deno.json" assert { type: "json" };
|
|||
import * as $0 from "./routes/[name].tsx";
|
||||
import * as $1 from "./routes/_404.tsx";
|
||||
import * as $2 from "./routes/_500.tsx";
|
||||
import * as $3 from "./routes/_middleware.ts";
|
||||
import * as $4 from "./routes/about.tsx";
|
||||
import * as $5 from "./routes/api/joke.ts";
|
||||
import * as $6 from "./routes/api/random-uuid.ts";
|
||||
import * as $7 from "./routes/countdown.tsx";
|
||||
import * as $8 from "./routes/dashboard.tsx";
|
||||
import * as $9 from "./routes/github/[username].tsx";
|
||||
import * as $10 from "./routes/index.tsx";
|
||||
import * as $11 from "./routes/login.tsx";
|
||||
import * as $12 from "./routes/logout.tsx";
|
||||
import * as $13 from "./routes/note.tsx";
|
||||
import * as $14 from "./routes/note/[id].tsx";
|
||||
import * as $15 from "./routes/note/create.tsx";
|
||||
import * as $16 from "./routes/plain.ts";
|
||||
import * as $17 from "./routes/register.tsx";
|
||||
import * as $18 from "./routes/route-config-example.tsx";
|
||||
import * as $19 from "./routes/search.tsx";
|
||||
import * as $3 from "./routes/_app.tsx";
|
||||
import * as $4 from "./routes/_middleware.ts";
|
||||
import * as $5 from "./routes/about.tsx";
|
||||
import * as $6 from "./routes/api/joke.ts";
|
||||
import * as $7 from "./routes/api/random-uuid.ts";
|
||||
import * as $8 from "./routes/countdown.tsx";
|
||||
import * as $9 from "./routes/dashboard.tsx";
|
||||
import * as $10 from "./routes/github/[username].tsx";
|
||||
import * as $11 from "./routes/index.tsx";
|
||||
import * as $12 from "./routes/login.tsx";
|
||||
import * as $13 from "./routes/logout.tsx";
|
||||
import * as $14 from "./routes/note.tsx";
|
||||
import * as $15 from "./routes/note/[id].tsx";
|
||||
import * as $16 from "./routes/note/create.tsx";
|
||||
import * as $17 from "./routes/plain.ts";
|
||||
import * as $18 from "./routes/register.tsx";
|
||||
import * as $19 from "./routes/route-config-example.tsx";
|
||||
import * as $20 from "./routes/search.tsx";
|
||||
import * as $$0 from "./islands/Countdown.tsx";
|
||||
import * as $$1 from "./islands/Counter.tsx";
|
||||
|
||||
|
@ -31,23 +32,24 @@ const manifest = {
|
|||
"./routes/[name].tsx": $0,
|
||||
"./routes/_404.tsx": $1,
|
||||
"./routes/_500.tsx": $2,
|
||||
"./routes/_middleware.ts": $3,
|
||||
"./routes/about.tsx": $4,
|
||||
"./routes/api/joke.ts": $5,
|
||||
"./routes/api/random-uuid.ts": $6,
|
||||
"./routes/countdown.tsx": $7,
|
||||
"./routes/dashboard.tsx": $8,
|
||||
"./routes/github/[username].tsx": $9,
|
||||
"./routes/index.tsx": $10,
|
||||
"./routes/login.tsx": $11,
|
||||
"./routes/logout.tsx": $12,
|
||||
"./routes/note.tsx": $13,
|
||||
"./routes/note/[id].tsx": $14,
|
||||
"./routes/note/create.tsx": $15,
|
||||
"./routes/plain.ts": $16,
|
||||
"./routes/register.tsx": $17,
|
||||
"./routes/route-config-example.tsx": $18,
|
||||
"./routes/search.tsx": $19,
|
||||
"./routes/_app.tsx": $3,
|
||||
"./routes/_middleware.ts": $4,
|
||||
"./routes/about.tsx": $5,
|
||||
"./routes/api/joke.ts": $6,
|
||||
"./routes/api/random-uuid.ts": $7,
|
||||
"./routes/countdown.tsx": $8,
|
||||
"./routes/dashboard.tsx": $9,
|
||||
"./routes/github/[username].tsx": $10,
|
||||
"./routes/index.tsx": $11,
|
||||
"./routes/login.tsx": $12,
|
||||
"./routes/logout.tsx": $13,
|
||||
"./routes/note.tsx": $14,
|
||||
"./routes/note/[id].tsx": $15,
|
||||
"./routes/note/create.tsx": $16,
|
||||
"./routes/plain.ts": $17,
|
||||
"./routes/register.tsx": $18,
|
||||
"./routes/route-config-example.tsx": $19,
|
||||
"./routes/search.tsx": $20,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Countdown.tsx": $$0,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"imports": {
|
||||
"@/": "./",
|
||||
"$std/": "https://deno.land/std@0.158.0/",
|
||||
"$fresh/": "https://deno.land/x/fresh@1.1.1/",
|
||||
"$fresh/": "https://deno.land/x/fresh@1.1.2/",
|
||||
"preact": "https://esm.sh/preact@10.11.0",
|
||||
"preact/": "https://esm.sh/preact@10.11.0/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.4",
|
||||
|
|
25
routes/_app.tsx
Normal file
25
routes/_app.tsx
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { type AppProps, Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { Page } from "@/components/Page.tsx";
|
||||
import { type PublicUser } from "@/types.ts";
|
||||
import { type ContextState } from "@/types.ts";
|
||||
|
||||
interface MyAppProps extends AppProps {
|
||||
user?: PublicUser;
|
||||
}
|
||||
|
||||
export const handler: Handlers<unknown, ContextState> = {
|
||||
async GET(_request: Request, context) {
|
||||
const user: Partial<ContextState["user"]> = context.state.user;
|
||||
if (user && "passwordDigest" in user) delete user.passwordDigest;
|
||||
return await context.render(context.state.user);
|
||||
},
|
||||
};
|
||||
|
||||
export default function App({ Component, ...props }: MyAppProps) {
|
||||
console.log("AppProps:", props);
|
||||
return (
|
||||
<Page user={props.user}>
|
||||
<Component></Component>
|
||||
</Page>
|
||||
);
|
||||
}
|
|
@ -2,12 +2,12 @@ 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";
|
||||
import { type ContextState, type PublicUser } from "@/types.ts";
|
||||
|
||||
export const handler: Handlers<unknown, ContextState> = {
|
||||
async GET(_request: Request, context) {
|
||||
const user: Partial<ContextState["user"]> = context.state.user;
|
||||
if (user && "passwordDigest" in user) delete user.passwordDigest;
|
||||
const user: PublicUser | undefined = context.state.user;
|
||||
if (user != undefined) delete user.passwordDigest;
|
||||
return await context.render(context.state.user);
|
||||
},
|
||||
};
|
||||
|
|
3
types.ts
3
types.ts
|
@ -51,3 +51,6 @@ export type TokenDigest = string;
|
|||
export interface ContextState {
|
||||
user?: PublicUser;
|
||||
}
|
||||
|
||||
function toPublicUser(user: User): PublicUser {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue