diff options
author | polwex <polwex@sortug.com> | 2025-09-17 15:56:00 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-09-17 15:56:00 +0700 |
commit | f0df4c7297a05bd592d8717b8997284c80fd0500 (patch) | |
tree | 2d38e079e971a2e98e78a0f7a3104f2bd3c5daeb /front/src/components/composer/Composer.tsx | |
parent | 387af8fc1603805b02ce03f8adba4fa73a954f7c (diff) |
argh
Diffstat (limited to 'front/src/components/composer/Composer.tsx')
-rw-r--r-- | front/src/components/composer/Composer.tsx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/front/src/components/composer/Composer.tsx b/front/src/components/composer/Composer.tsx new file mode 100644 index 0000000..795188e --- /dev/null +++ b/front/src/components/composer/Composer.tsx @@ -0,0 +1,67 @@ +import useLocalState from "@/state/state"; +import type { Poast } from "@/types/trill"; +import Sigil from "@/components/Sigil"; +import { useState, type FormEvent } from "react"; +import type { ComposerData } from "@/types/ui"; +import Snippets, { ReplySnippet } from "./Snippets"; +import toast from "react-hot-toast"; +import { useLocation } from "wouter"; + +function Composer({ + isAnon, + replying, +}: { + isAnon?: boolean; + replying?: Poast; +}) { + const [loc, navigate] = useLocation(); + const { api, composerData } = useLocalState(); + const our = api!.airlock.our!; + const [input, setInput] = useState(replying ? `${replying}: ` : ""); + async function poast(e: FormEvent<HTMLFormElement>) { + e.preventDefault(); + // TODO + // const parent = replying ? replying : null; + // const tokens = tokenize(input); + // const post: SentPoast = { + // host: parent ? parent.host : our, + // author: our, + // thread: parent ? parent.thread : null, + // parent: parent ? parent.id : null, + // contents: input, + // read: openLock, + // write: openLock, + // tags: input.match(HASHTAGS_REGEX) || [], + // }; + // TODO make it user choosable + const res = await api!.addPost(input); + if (res) { + setInput(""); + toast.success("post sent"); + navigate(`/feed/${our}`); + } + } + const placeHolder = isAnon ? "> be me" : "What's going on in Urbit"; + return ( + <form id="composer" onSubmit={poast}> + <div className="sigil"> + <Sigil patp={our} size={48} /> + </div> + + {composerData && composerData.type === "reply" && ( + <ReplySnippet post={composerData?.post} /> + )} + <input + value={input} + onInput={(e) => setInput(e.currentTarget.value)} + placeholder={placeHolder} + /> + {composerData && composerData.type === "quote" && ( + <Snippets post={composerData?.post} /> + )} + <button type="submit">Post</button> + </form> + ); +} + +export default Composer; |