Back
Version 12
10/31/2023
/** @jsxImportSource https://esm.sh/react */
import { html } from "https://esm.town/v/stevekrouse/html";
import { renderToString } from "npm:react-dom/server";
// TODO create todos database in turso
const ToDo = (todo) => {
// return html`<li data-id=${todo.id}>
// <label>
// <input hx-delete="/" hx-target="[data-id='${todo.id}']" hx-swap="delete" style='display:inline;margin-right:0.5rem;' type='checkbox' name="id" value=${todo.id} />
// ${todo.name}
// </label>
// </li>`;
};
function deleteTodo(req: Request) {
}
async function addTodo(req: Request) {
const name = (await req.json()).name.substring(0, 256).trim();
if (!name) return new Response("Cannot add Todo without name", { status: 400 });
const todo = {
id: crypto.randomUUID(),
name,
};
// TODO add to turso
return Response.json("ok");
}
export let todo_list = async (req, res) => {
if (req.method === "POST") return addTodo(req);
if (req.method === "DELETE") return deleteTodo(req);
else return html(renderToString(
<html>
<head>
<title>TODO</title>
stevekrouse-todo_list.web.val.run
Updated: February 22, 2024