@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 41 lines 1.25 KB
Raw
1 import { useState, type FormEvent } from "react";
2
3 export const NoteForm = ({ onCreate }: { onCreate: (body: string) => Promise<void> }) => {
4 const [body, setBody] = useState("");
5 const [pending, setPending] = useState(false);
6
7 const submit = async (event: FormEvent<HTMLFormElement>) => {
8 event.preventDefault();
9 const trimmed = body.trim();
10 if (trimmed.length === 0 || pending) return;
11 setPending(true);
12 try {
13 await onCreate(trimmed);
14 setBody("");
15 } finally {
16 setPending(false);
17 }
18 };
19
20 return (
21 <form onSubmit={submit} className="flex flex-col gap-3 sm:flex-row">
22 <label className="sr-only" htmlFor="note-body">
23 Note
24 </label>
25 <input
26 id="note-body"
27 value={body}
28 onChange={(event) => setBody(event.target.value)}
29 placeholder="Write a note…"
30 className="min-w-0 flex-1 rounded-xl border border-slate-700 bg-slate-900 px-4 py-3 text-slate-100 outline-none ring-sky-400 focus:ring-2"
31 />
32 <button
33 type="submit"
34 disabled={pending}
35 className="rounded-xl bg-sky-500 px-5 py-3 font-medium text-slate-950 hover:bg-sky-400 disabled:opacity-60"
36 >
37 {pending ? "Saving…" : "Add note"}
38 </button>
39 </form>
40 );
41 };