summaryrefslogtreecommitdiff
path: root/front/src/components/feed/Composer.tsx
blob: 27da392c44f96dbd1fccdaaf790700f27ff6ae98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { openLock } from "@/logic/bunts";
import { HASHTAGS_REGEX } from "@/logic/constants";
import useLocalState from "@/state/state";
import type { Poast, SentPoast } from "@/types/trill";
import Sigil from "@/components/Sigil";
import { useState } from "react";

function Composer({
  isAnon,
  replying,
}: {
  isAnon?: boolean;
  replying?: Poast;
}) {
  const { api, keys } = useLocalState();
  const our = api!.airlock.our!;
  const [input, setInput] = useState(replying ? `${replying}: ` : "");
  async function poast() {
    // 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 pubkey = keys[0]!;
    await api!.addPost(pubkey, input);
  }
  const placeHolder = isAnon ? "> be me" : "What's going on in Urbit";
  return (
    <div id="composer">
      <div className="sigil">
        <Sigil patp={our} size={48} />
      </div>
      <input
        value={input}
        onInput={(e) => setInput(e.currentTarget.value)}
        placeholder={placeHolder}
      />
      <button onClick={poast}>Post</button>
    </div>
  );
}

export default Composer;