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

main
tsx 145 lines 3.84 KB
Raw
1 import { useAtomSet, useAtomValue } from "@effect/atom-react";
2 import { createFileRoute } from "@tanstack/react-router";
3 import * as AsyncResult from "effect/reactivity/AsyncResult";
4 import { useState } from "react";
5 import { createTodoAtom, deleteTodoAtom, listTodosAtom, toggleTodoAtom } from "../rpc-client.ts";
6
7 export const Route = createFileRoute("/")({
8 component: Home,
9 });
10
11 function Home() {
12 return (
13 <main style={{ maxWidth: 640, margin: "0 auto", padding: "4rem 1.5rem" }}>
14 <h1 style={{ margin: 0, fontSize: "2.25rem" }}>Todos</h1>
15 <p style={{ marginTop: "0.75rem", color: "#475569", lineHeight: 1.6 }}>
16 TanStack Start UI &rarr; <code>AtomRpc</code> client &rarr; Effect RPC worker &rarr; Drizzle
17 &rarr; Neon Postgres.
18 </p>
19 <section style={{ marginTop: "2rem" }}>
20 <TodoForm />
21 <TodoList />
22 </section>
23 </main>
24 );
25 }
26
27 function TodoForm() {
28 const createTodo = useAtomSet(createTodoAtom);
29
30 const [text, setText] = useState("");
31
32 const submit = (e: React.SubmitEvent) => {
33 e.preventDefault();
34 const value = text.trim();
35 if (!value) return;
36 createTodo({ payload: { text: value }, reactivityKeys: ["todos"] });
37 setText("");
38 };
39
40 return (
41 <form onSubmit={submit} style={{ display: "flex", gap: "0.5rem" }}>
42 <input
43 value={text}
44 onChange={(e) => setText(e.target.value)}
45 placeholder="What needs doing?"
46 style={{
47 flex: 1,
48 padding: "0.6rem 0.75rem",
49 borderRadius: 8,
50 border: "1px solid #cbd5e1",
51 fontSize: "1rem",
52 }}
53 />
54 <button type="submit" style={primaryButton}>
55 Add
56 </button>
57 </form>
58 );
59 }
60
61 function TodoList() {
62 const atom = useAtomValue(listTodosAtom);
63 const toggleTodo = useAtomSet(toggleTodoAtom);
64 const deleteTodo = useAtomSet(deleteTodoAtom);
65
66 const todos = AsyncResult.getOrElse(atom, () => []);
67
68 if ((AsyncResult.isWaiting(atom) && !todos.length) || typeof window === "undefined") {
69 return <p style={{ color: "#94a3b8", marginTop: "1.5rem" }}>Loading todos…</p>;
70 }
71
72 if (!todos.length) {
73 return <p style={{ color: "#94a3b8", marginTop: "1.5rem" }}>No todos yet — add one above.</p>;
74 }
75
76 return (
77 <ul style={{ listStyle: "none", padding: 0, marginTop: "1.5rem" }}>
78 {todos.map((todo) => (
79 <li
80 key={todo.id}
81 style={{
82 display: "flex",
83 alignItems: "center",
84 gap: "0.75rem",
85 padding: "0.6rem 0",
86 borderBottom: "1px solid #e2e8f0",
87 }}
88 >
89 <input
90 type="checkbox"
91 checked={todo.done}
92 onChange={() =>
93 toggleTodo({
94 payload: { id: todo.id, done: !todo.done },
95 reactivityKeys: ["todos"],
96 })
97 }
98 style={{ width: 18, height: 18 }}
99 />
100 <span
101 style={{
102 flex: 1,
103 textDecoration: todo.done ? "line-through" : "none",
104 color: todo.done ? "#94a3b8" : "#0f172a",
105 }}
106 >
107 {todo.text}
108 </span>
109 <button
110 type="button"
111 onClick={() =>
112 deleteTodo({
113 payload: { id: todo.id },
114 reactivityKeys: ["todos"],
115 })
116 }
117 style={ghostButton}
118 >
119 Delete
120 </button>
121 </li>
122 ))}
123 </ul>
124 );
125 }
126
127 const primaryButton: React.CSSProperties = {
128 padding: "0.6rem 1.1rem",
129 border: "none",
130 borderRadius: 8,
131 background: "#0f172a",
132 color: "#fff",
133 cursor: "pointer",
134 fontSize: "1rem",
135 };
136
137 const ghostButton: React.CSSProperties = {
138 padding: "0.35rem 0.6rem",
139 border: "none",
140 borderRadius: 6,
141 background: "transparent",
142 color: "#ef4444",
143 cursor: "pointer",
144 fontSize: "0.875rem",
145 };