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((s) => ({ api: s.api, composerData: s.composerData, })); const our = api!.airlock.our!; const [input, setInput] = useState(replying ? `${replying}: ` : ""); async function poast(e: FormEvent) { 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 (
{composerData && composerData.type === "reply" && ( )} setInput(e.currentTarget.value)} placeholder={placeHolder} /> {composerData && composerData.type === "quote" && ( )} ); } export default Composer;