todo app done
parent
de5a74e593
commit
65c49c7280
@ -1,21 +0,0 @@
|
||||
import { Elysia } from "elysia";
|
||||
import { swagger } from "@elysiajs/swagger";
|
||||
import { staticPlugin } from "@elysiajs/static";
|
||||
import { todosController } from "./controllers/todos";
|
||||
|
||||
const app = new Elysia({
|
||||
name: "@app/main",
|
||||
})
|
||||
// .use(swagger())
|
||||
.use(staticPlugin())
|
||||
.use(todosController)
|
||||
.listen(3000);
|
||||
|
||||
export type App = typeof app;
|
||||
|
||||
console.log(`app is listening on ${app.server?.hostname}:${app.server?.port}`);
|
||||
|
||||
app
|
||||
.handle(new Request("http://localhost:3000/todos"))
|
||||
.then((res) => res.text())
|
||||
.then(console.log);
|
@ -0,0 +1,32 @@
|
||||
import { Elysia } from "elysia";
|
||||
import { swagger } from "@elysiajs/swagger";
|
||||
import { staticPlugin } from "@elysiajs/static";
|
||||
import { todosController } from "./controllers/todos";
|
||||
import { BaseHtml } from "./views/base";
|
||||
import Html from "@kitajs/html";
|
||||
|
||||
const app = new Elysia({
|
||||
name: "@app/main",
|
||||
})
|
||||
// .use(swagger())
|
||||
// .use(staticPlugin())
|
||||
.use(todosController)
|
||||
.get("/", ({ html }) =>
|
||||
html(
|
||||
<BaseHtml>
|
||||
<body
|
||||
class="flex w-full h-screen justify-center items-center"
|
||||
hx-get="/todos"
|
||||
hx-swap="innerHTML"
|
||||
hx-trigger="load"
|
||||
/>
|
||||
</BaseHtml>
|
||||
)
|
||||
)
|
||||
.listen(3000);
|
||||
|
||||
export type App = typeof app;
|
||||
|
||||
console.log(
|
||||
`app is listening on http://${app.server?.hostname}:${app.server?.port}`
|
||||
);
|
@ -0,0 +1,18 @@
|
||||
import Html from "@kitajs/html";
|
||||
|
||||
export const BaseHtml = ({ children }: Html.PropsWithChildren) => `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>THE BETH STACK</title>
|
||||
<script src="https://unpkg.com/htmx.org@1.9.3"></script>
|
||||
<script src="https://unpkg.com/hyperscript.org@0.9.9"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@unocss/runtime"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unocss/reset/tailwind.min.css">
|
||||
</head>
|
||||
|
||||
${children}
|
||||
`;
|
@ -1,11 +0,0 @@
|
||||
import type { Todo } from "../model/todo";
|
||||
import Html from "@kitajs/html";
|
||||
|
||||
export const TodoItem = (todo: Todo) => {
|
||||
return (
|
||||
<li>
|
||||
<input type="checkbox" checked={todo.completed} />
|
||||
<span>{todo.content}</span>
|
||||
</li>
|
||||
);
|
||||
};
|
@ -0,0 +1,58 @@
|
||||
import type { Todo } from "../model/todo";
|
||||
import Html from "@kitajs/html";
|
||||
|
||||
export function TodoItem({ content, completed, id }: Todo) {
|
||||
return (
|
||||
<div class="flex flex-row space-x-3">
|
||||
<p>{content}</p>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={completed}
|
||||
hx-post={`/todos/toggle/${id}`}
|
||||
hx-swap="outerHTML"
|
||||
hx-target="closest div"
|
||||
/>
|
||||
<button
|
||||
class="text-red-500"
|
||||
hx-delete={`/todos/${id}`}
|
||||
hx-swap="outerHTML"
|
||||
hx-target="closest div"
|
||||
>
|
||||
X
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TodoList({ todos }: { todos: Todo[] }) {
|
||||
return (
|
||||
<div>
|
||||
{todos.map((todo) => (
|
||||
<TodoItem {...todo} />
|
||||
))}
|
||||
<TodoForm />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TodoForm() {
|
||||
return (
|
||||
<form
|
||||
class="flex flex-row space-x-3"
|
||||
hx-post="/todos"
|
||||
hx-swap="beforebegin"
|
||||
_="on submit target.reset()"
|
||||
>
|
||||
<select name="content" class="border border-black">
|
||||
<option value="" disabled="true" selected="true">
|
||||
Select a Todo
|
||||
</option>
|
||||
<option value="beth">Learn the BETH stack</option>
|
||||
<option value="vim">Learn vim</option>
|
||||
<option value="like">Like the video</option>
|
||||
<option value="sub">Subscribe to Ethan</option>
|
||||
</select>
|
||||
<button type="submit">Add</button>
|
||||
</form>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue