From 03b0e4c6f3da41ce5bf462a95b1fc68f308092e4 Mon Sep 17 00:00:00 2001 From: nyaomaru Date: Sun, 11 Aug 2024 10:49:59 +0900 Subject: [PATCH] refactor: refactor --- src/components/Card.tsx | 2 +- src/components/Link.tsx | 6 ++-- src/islands/Counter.tsx | 6 ++-- src/islands/NextContentButton.tsx | 24 +++++++-------- src/routes/_500.tsx | 2 +- src/routes/_layout.tsx | 12 ++++---- src/routes/_middleware.ts | 14 ++++----- src/routes/api/random-uuid.ts | 12 ++++---- src/routes/greet/_middleware.ts | 12 ++++---- src/routes/index.tsx | 48 +++++++++++++++++++----------- src/routes/partials/about/[id].tsx | 38 +++++++++++------------ 11 files changed, 95 insertions(+), 81 deletions(-) diff --git a/src/components/Card.tsx b/src/components/Card.tsx index e40b1a9..c4ee85a 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -5,7 +5,7 @@ export function Card(props: JSX.HTMLAttributes) {
{props.title}
-
{props.children}
+
{props.children}
); diff --git a/src/components/Link.tsx b/src/components/Link.tsx index f809af6..406b063 100644 --- a/src/components/Link.tsx +++ b/src/components/Link.tsx @@ -1,12 +1,14 @@ +import { JSX } from "preact"; + type LinkProps = { text: string; href: string; color?: "primary" | "secondary"; -}; +} & JSX.HTMLAttributes; export function Link({ color = "primary", ...props }: LinkProps) { return ( - + -
+ +

{count}

-
{children}
+
{children}
); } diff --git a/src/islands/NextContentButton.tsx b/src/islands/NextContentButton.tsx index 7ec3525..156c359 100644 --- a/src/islands/NextContentButton.tsx +++ b/src/islands/NextContentButton.tsx @@ -1,20 +1,20 @@ import { useSignal } from "@preact/signals"; interface Props { - name: string; + name: string; } export default function NextContentButton({ name }: Props) { - const id = useSignal(0); + const id = useSignal(0); - return ( -
(id.value += 1)} - > - {name} - - ); + return ( + (id.value += 1)} + > + {name} + + ); } diff --git a/src/routes/_500.tsx b/src/routes/_500.tsx index 24699d0..544455c 100644 --- a/src/routes/_500.tsx +++ b/src/routes/_500.tsx @@ -1,5 +1,5 @@ import { PageProps } from "$fresh/server.ts"; export default function Error500Page({ error }: PageProps) { - return

500 internal error: {(error as Error).message}

; + return

500 internal error: {(error as Error).message}

; } diff --git a/src/routes/_layout.tsx b/src/routes/_layout.tsx index 1bfc504..e90f0fa 100644 --- a/src/routes/_layout.tsx +++ b/src/routes/_layout.tsx @@ -1,10 +1,10 @@ import { PageProps } from "$fresh/server.ts"; export default function Layout({ Component, state }: PageProps) { - // do something with state here - return ( -
- -
- ); + // do something with state here + return ( +
+ +
+ ); } diff --git a/src/routes/_middleware.ts b/src/routes/_middleware.ts index a05765c..d26be09 100644 --- a/src/routes/_middleware.ts +++ b/src/routes/_middleware.ts @@ -1,15 +1,15 @@ import { FreshContext } from "$fresh/server.ts"; interface State { - data: string; + data: string; } export async function handler( - _req: Request, - ctx: FreshContext, + _req: Request, + ctx: FreshContext, ) { - ctx.state.data = "myData"; - const resp = await ctx.next(); - resp.headers.set("server", "fresh server"); - return resp; + ctx.state.data = "myData"; + const resp = await ctx.next(); + resp.headers.set("server", "fresh server"); + return resp; } diff --git a/src/routes/api/random-uuid.ts b/src/routes/api/random-uuid.ts index d28d2e3..4785eae 100644 --- a/src/routes/api/random-uuid.ts +++ b/src/routes/api/random-uuid.ts @@ -1,10 +1,10 @@ import { Handlers } from "$fresh/server.ts"; export const handler: Handlers = { - GET(_req) { - const uuid = crypto.randomUUID(); - return new Response(JSON.stringify(uuid), { - headers: { "Content-Type": "application/json" }, - }); - }, + GET(_req) { + const uuid = crypto.randomUUID(); + return new Response(JSON.stringify(uuid), { + headers: { "Content-Type": "application/json" }, + }); + }, }; diff --git a/src/routes/greet/_middleware.ts b/src/routes/greet/_middleware.ts index 1bbe6e0..077cc57 100644 --- a/src/routes/greet/_middleware.ts +++ b/src/routes/greet/_middleware.ts @@ -1,10 +1,10 @@ import { FreshContext } from "$fresh/server.ts"; export async function handler(_req: Request, ctx: FreshContext) { - const currentName = ctx.params.name; - if (currentName === "Bob") { - ctx.params.name = "super-bob"; - } - const resp = await ctx.next(); - return resp; + const currentName = ctx.params.name; + if (currentName === "Bob") { + ctx.params.name = "super-bob"; + } + const resp = await ctx.next(); + return resp; } diff --git a/src/routes/index.tsx b/src/routes/index.tsx index a74195e..99b9084 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -22,25 +22,37 @@ export default function Home({ data }: PageProps) { height="128" alt="the Fresh logo: a sliced lemon dripping with juice" /> -

Nyaomaru Deno Sample

-

- I am a cat being!! -

- -

This text is rendered on the server

-
-
- - - - +
+

Nyaomaru Deno Sample

+

+ I am a cat being!! +

-
- - + +
+

Counter Test

+
+ +

This text is rendered on the server

+
+
+
+ +
+

Page Buttons

+
+ + + + +
+
+ + +

diff --git a/src/routes/partials/about/[id].tsx b/src/routes/partials/about/[id].tsx index df7bbba..cbd10d9 100644 --- a/src/routes/partials/about/[id].tsx +++ b/src/routes/partials/about/[id].tsx @@ -2,34 +2,34 @@ import { defineRoute, RouteConfig } from "$fresh/server.ts"; import { Partial } from "$fresh/runtime.ts"; const contents = [ - "This is the documentation page. It should contain all the \n information you need to get started with the project.", - "bla bla bla", + "This is the documentation page. It should contain all the \n information you need to get started with the project.", + "bla bla bla", ]; const loadContent = async (id: string) => { - const currentContent = contents[Number(id) % 2]; + const currentContent = contents[Number(id) % 2]; - return ( -

-

Documentation: {id}

-

- {currentContent} -

-
- ); + return ( +
+

Documentation: {id}

+

+ {currentContent} +

+
+ ); }; export const config: RouteConfig = { - skipAppWrapper: true, - skipInheritedLayouts: true, + skipAppWrapper: true, + skipInheritedLayouts: true, }; export default defineRoute(async (req, ctx) => { - const content = await loadContent(ctx.params.id); + const content = await loadContent(ctx.params.id); - return ( - - {content} - - ); + return ( + + {content} + + ); });