summaryrefslogtreecommitdiff
path: root/gui/src/components/feed/PostList.tsx
blob: 3659bde297669ee9eee87719e9a236a3ac302de7 (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
53
54
55
import TrillPost from "@/components/post/Post";
import type { FC } from "@/types/trill";
import useLocalState from "@/state/state";
import type { UserType } from "@/types/nostrill";
import { isValidPatp } from "urbit-ob";
// import { useEffect } from "react";
// import { useQueryClient } from "@tanstack/react-query";
// import { toFull } from "../thread/helpers";

function TrillFeed({ data, refetch }: { data: FC; refetch: Function }) {
  const { profiles } = useLocalState((s) => ({ profiles: s.profiles }));
  // const qc = useQueryClient();
  // useEffect(() => {
  //   Object.values(data.feed).forEach((poast) => {
  //     const queryKey = ["trill-thread", poast.host, poast.id];
  //     const existing = qc.getQueryData(queryKey);
  //     if (!existing || !("fpost" in (existing as any))) {
  //       qc.setQueryData(queryKey, {
  //         fpost: toFull(poast),
  //       });
  //     }
  //   });
  // }, [data]);
  return (
    <>
      {Object.keys(data.feed)
        // omit replies
        .filter((i) => !data.feed[i].parent)
        .sort()
        .reverse()
        // .slice(0, 50)
        .map((i) => {
          const poast = data.feed[i];
          const user: UserType = poast.event
            ? { nostr: poast.event.pubkey }
            : isValidPatp(poast.author)
              ? { urbit: poast.author }
              : { nostr: poast.author };
          const userString = "urbit" in user ? user.urbit : user.nostr;
          const profile = profiles.get(userString);
          return (
            <TrillPost
              key={i}
              poast={poast}
              user={user}
              profile={profile}
              refetch={refetch}
            />
          );
        })}
    </>
  );
}

export default TrillFeed;