The best way to control Claude Code, Codex and more from any computer or phone

main
ts 82 lines 2.28 KB
Raw
1 import { Button } from "@foldkit/ui";
2 import { Schema } from "effect";
3 import { Runtime, type Update } from "foldkit";
4 import type { Document, HtmlBuilder } from "foldkit/html";
5 import { defineMessageUnion } from "foldkit/message";
6 import { modifyFields } from "foldkit/struct";
7
8 // MODEL
9
10 export const Model = Schema.Struct({ count: Schema.Number });
11 export type Model = typeof Model.Type;
12
13 // MESSAGE
14
15 export const Message = defineMessageUnion({
16 ClickedDecrement: {},
17 ClickedIncrement: {},
18 ClickedReset: {},
19 });
20 export type Message = typeof Message.Type;
21
22 // UPDATE
23
24 export const update = (model: Model, message: Message) =>
25 Message.match<Update.Return<Model, Message>>(message, {
26 ClickedDecrement: () => ({
27 model: modifyFields(model, { count: (count) => count - 1 }),
28 }),
29 ClickedIncrement: () => ({
30 model: modifyFields(model, { count: (count) => count + 1 }),
31 }),
32 ClickedReset: () => ({ model: modifyFields(model, { count: () => 0 }) }),
33 });
34
35 // INIT
36
37 export const init: Runtime.ApplicationInit<Model, Message> = () => ({
38 model: { count: 0 },
39 });
40
41 // VIEW
42
43 export const view = (model: Model, h: HtmlBuilder<Message>): Document => ({
44 title: `Counter: ${model.count}`,
45 body: h.div(
46 [h.Class("min-h-screen bg-white flex flex-col items-center justify-center gap-6 p-6")],
47 [
48 h.p([h.Class("text-6xl font-bold text-gray-800")], [model.count.toString()]),
49 h.div(
50 [h.Class("flex flex-wrap justify-center gap-4")],
51 [
52 Button.view(
53 {
54 onClick: Message.ClickedDecrement(),
55 toView: (attributes) => h.button([...attributes.button, h.Class(buttonStyle)], ["-"]),
56 },
57 h,
58 ),
59 Button.view(
60 {
61 onClick: Message.ClickedReset(),
62 toView: (attributes) =>
63 h.button([...attributes.button, h.Class(buttonStyle)], ["Reset"]),
64 },
65 h,
66 ),
67 Button.view(
68 {
69 onClick: Message.ClickedIncrement(),
70 toView: (attributes) => h.button([...attributes.button, h.Class(buttonStyle)], ["+"]),
71 },
72 h,
73 ),
74 ],
75 ),
76 ],
77 ),
78 });
79
80 // STYLE
81
82 const buttonStyle = "bg-black text-white hover:bg-gray-700 px-4 py-2 transition";