1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/** @jsx jsx */
import { FC, jsx } from "https://deno.land/x/hono@v3.11.7/middleware.ts";
import { Hono } from "https://deno.land/x/hono@v3.11.7/mod.ts";
import { blob } from "https://esm.town/v/std/blob";
const app = new Hono();
const TopBar: FC = () => (
<div class="w-full p-4 flex font-bold place-content-between flex-row">
<a href="/">⚙️ Control Panel</a>
<a href="https://www.val.town/v/wilhelm/HTHTMX">&lt;/&gt;</a>
</div>
);
const Layout: FC = ({ children, title = "Control Panel" }) => (
<html lang="en" hidden>
<head>
<link
rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>⚙️</text></svg>"
/>
<title>{title}</title>
<script src="https://unpkg.com/htmx.org@1.9.9"></script>
<script type="module" src="https://cdn.skypack.dev/twind/shim"></script>
</head>
<body class="h-screen flex flex-col bg-gray-600 text-gray-800">
<TopBar />
{children}
</body>
</html>
);
const Toggle = ({ on }) => (
<div id="toggleSection">
<div class="font-bold text-xl flex-col">
{on ? "It's so on" : "You should turn it on"}
</div>
<div class="flex items-center justify-center p-2">
<input
hx-put="/toggle"
hx-swap="outerHTML"
hx-target="#toggleSection"
type="checkbox"
name="toggle"
checked={on}
/>
</div>
</div>
);
const Home: FC = async () => (
<main class="flex-grow flex items-center justify-center">
<Toggle on={(await blob.getJSON("bool"))?.toggle ?? false} />
</main>
);
app.get("/", (c) =>
c.html(
<Layout>
<Home />
</Layout>,
));
app.put("/toggle", async (c) => {
const on = Boolean((await c.req.formData()).get("toggle"));
await blob.setJSON("bool", { toggle: on });
return c.html(<Toggle on={on} />);
});
export default app.fetch;