-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from mbicknese/demo-upgrades
Demo upgrades
- Loading branch information
Showing
20 changed files
with
168 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ | |
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# Fresh build directory | ||
_fresh/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,12 @@ | ||
import { JSX } from "preact"; | ||
import { | ||
cva, | ||
type VariantProps, | ||
} from "https://esm.sh/[email protected]"; | ||
// import { cva, type VariantProps } from "npm:class-variance-authority" | ||
import { twMerge } from "https://esm.sh/[email protected]"; | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "bg-primary text-primary-foreground hover:bg-primary/90", | ||
destructive: | ||
"bg-destructive text-destructive-foreground hover:bg-destructive/90", | ||
outline: | ||
"border border-input hover:bg-accent hover:text-accent-foreground", | ||
secondary: | ||
"bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
ghost: "hover:bg-accent hover:text-accent-foreground", | ||
link: "underline-offset-4 hover:underline text-primary", | ||
}, | ||
size: { | ||
default: "h-10 py-2 px-4", | ||
sm: "h-9 px-3 rounded-md", | ||
lg: "h-11 px-8 rounded-md", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
}, | ||
); | ||
|
||
export interface ButtonProps | ||
extends | ||
JSX.HTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = ( | ||
{ className, variant, size, asChild = false, ...props }: ButtonProps, | ||
) => { | ||
// const Comp = asChild ? Slot : "button" | ||
export default function Button(props: JSX.HTMLAttributes<HTMLButtonElement>) { | ||
return ( | ||
<button | ||
className={twMerge(buttonVariants({ variant, size, className }))} | ||
{...props} | ||
class={`px-3 py-2 bg-white rounded border(gray-500 2) hover:bg-gray-200 active:bg-gray-300 disabled:(opacity-50 cursor-not-allowed) ${ | ||
props.class ?? "" | ||
}`} | ||
/> | ||
); | ||
}; | ||
|
||
export { Button, buttonVariants }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
import { JSX } from "preact"; | ||
import { twMerge } from "https://esm.sh/[email protected]"; | ||
|
||
export interface InputProps extends JSX.HTMLAttributes<HTMLInputElement> {} | ||
|
||
const Input = ({ className, type, ...props }: InputProps) => { | ||
export default function Input(props: JSX.HTMLAttributes<HTMLInputElement>) { | ||
return ( | ||
<input | ||
type={type} | ||
className={twMerge( | ||
"flex h-10 w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", | ||
className as string, | ||
)} | ||
{...props} | ||
class={`px-3 py-2 bg-white rounded border(gray-500 2) disabled:(opacity-50 cursor-not-allowed) ${ | ||
props.class ?? "" | ||
}`} | ||
/> | ||
); | ||
}; | ||
|
||
export { Input }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
{ | ||
"lock": false, | ||
"tasks": { | ||
"start": "deno run --unstable -A --watch=static/,routes/ dev.ts" | ||
"start": "deno run --unstable -A --watch=static/,routes/ dev.ts", | ||
"build": "deno run -A dev.ts build", | ||
"preview": "deno run -A main.ts" | ||
}, | ||
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }, | ||
"importMap": "./import_map.json", | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "preact" | ||
} | ||
"lint": { "rules": { "tags": ["fresh", "recommended"] } }, | ||
"exclude": ["**/_fresh/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
// DO NOT EDIT. This file is generated by fresh. | ||
// DO NOT EDIT. This file is generated by Fresh. | ||
// This file SHOULD be checked into source version control. | ||
// This file is automatically updated during development when running `dev.ts`. | ||
|
||
import config from "./deno.json" assert { type: "json" }; | ||
import * as $0 from "./routes/[name].tsx"; | ||
import * as $1 from "./routes/_middleware.ts"; | ||
import * as $2 from "./routes/api/joke.ts"; | ||
import * as $3 from "./routes/index.tsx"; | ||
import * as $$0 from "./islands/Counter.tsx"; | ||
import * as $$1 from "./islands/SubmitTask.tsx"; | ||
import * as $_app from "./routes/_app.tsx"; | ||
import * as $_middleware from "./routes/_middleware.ts"; | ||
import * as $index from "./routes/index.tsx"; | ||
|
||
import { type Manifest } from "$fresh/server.ts"; | ||
|
||
const manifest = { | ||
routes: { | ||
"./routes/[name].tsx": $0, | ||
"./routes/_middleware.ts": $1, | ||
"./routes/api/joke.ts": $2, | ||
"./routes/index.tsx": $3, | ||
}, | ||
islands: { | ||
"./islands/Counter.tsx": $$0, | ||
"./islands/SubmitTask.tsx": $$1, | ||
"./routes/_app.tsx": $_app, | ||
"./routes/_middleware.ts": $_middleware, | ||
"./routes/index.tsx": $index, | ||
}, | ||
islands: {}, | ||
baseUrl: import.meta.url, | ||
config, | ||
}; | ||
} satisfies Manifest; | ||
|
||
export default manifest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
{ | ||
"imports": { | ||
"$fresh/": "https://deno.land/x/fresh@1.1.6/", | ||
"preact": "https://esm.sh/preact@10.13.1", | ||
"preact/": "https://esm.sh/preact@10.13.1/", | ||
"$fresh/": "https://deno.land/x/fresh@1.6.1/", | ||
"preact": "https://esm.sh/preact@10.19.2", | ||
"preact/": "https://esm.sh/preact@10.19.2/", | ||
"preact-render-to-string": "https://esm.sh/*[email protected]", | ||
"@preact/signals": "https://esm.sh/*@preact/[email protected]", | ||
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]", | ||
"twind": "https://esm.sh/[email protected]", | ||
"twind/": "https://esm.sh/[email protected]/", | ||
"$std/": "https://deno.land/[email protected]/" | ||
"@preact/signals": "https://esm.sh/*@preact/[email protected]", | ||
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]", | ||
"tailwindcss": "npm:[email protected]", | ||
"tailwindcss/": "npm:/[email protected]/", | ||
"tailwindcss/plugin": "npm:/[email protected]/plugin.js", | ||
"$std/": "https://deno.land/[email protected]/", | ||
"pentagon": "https://deno.land/x/[email protected]/mod.ts", | ||
"x-pentagon": "../../mod.ts", | ||
"zod": "https://deno.land/x/[email protected]/mod.ts" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PageProps } from "$fresh/server.ts"; | ||
|
||
export default function App({ Component }: PageProps) { | ||
return ( | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="/styles.css" /> | ||
<title>demo</title> | ||
</head> | ||
<body> | ||
<Component /> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
import { MiddlewareHandlerContext } from "$fresh/server.ts"; | ||
import { createUser } from "../lib/db.ts"; | ||
import { getCookies, setCookie } from "$std/http/cookie.ts"; | ||
import { FreshContext } from "$fresh/server.ts"; | ||
import { createUser, db } from "../lib/db.ts"; | ||
|
||
interface State { | ||
data: string; | ||
} | ||
type State = { | ||
user: { id: string }; | ||
}; | ||
|
||
export async function handler( | ||
_: Request, | ||
ctx: MiddlewareHandlerContext<State>, | ||
req: Request, | ||
ctx: FreshContext<State>, | ||
) { | ||
const resp = await ctx.next(); | ||
const userId = resp.headers.get("userid"); | ||
|
||
if (!userId) { | ||
const createdUser = await createUser(); | ||
if (!createdUser) { | ||
return new Response(`Oops! Something went wrong!`, { status: 500 }); | ||
const cookies = getCookies(req.headers); | ||
if (ctx.destination !== "route" || cookies.userid != null) { | ||
if (cookies.userid) { | ||
ctx.state.user = await db.users.findFirst({ | ||
where: { id: cookies.userid }, | ||
}); | ||
} | ||
const expirationDate = new Date(); | ||
expirationDate.setMonth(expirationDate.getMonth() + 1); | ||
resp.headers.set( | ||
`set-cookie`, | ||
`userid=${createdUser.id}; Path=/; Expires=${expirationDate.toUTCString()}; HttpOnly`, | ||
); | ||
return ctx.next(); | ||
} | ||
|
||
const createdUser = await createUser(); | ||
if (!createdUser) { | ||
return new Response(`Oops! Something went wrong!`, { status: 500 }); | ||
} | ||
ctx.state.user = createdUser; | ||
|
||
const resp = await ctx.next(); | ||
const expirationDate = new Date(); | ||
expirationDate.setMonth(expirationDate.getMonth() + 1); | ||
setCookie(resp.headers, { | ||
name: "userid", | ||
value: createdUser.id, | ||
expires: expirationDate, | ||
}); | ||
|
||
return resp; | ||
} |
Oops, something went wrong.