summaryrefslogtreecommitdiff
path: root/gui/src/pages/Feed.tsx
blob: 16a5ea134c7009cc0d7e5d6ccfcc5f65f685857d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import "@/styles/trill.css";
import "@/styles/feed.css";
import PostList from "@/components/feed/PostList";
import useLocalState from "@/state/state";
import { useParams } from "wouter";
import spinner from "@/assets/triangles.svg";
import { useState } from "react";
import Composer from "@/components/composer/Composer";
import { ErrorPage } from "@/pages/Error";
import NostrFeed from "@/components/nostr/Feed";
import { consolidateFeeds, disaggregate } from "@/logic/nostrill";

type FeedType = "urbit" | "following" | "nostr";
function Loader() {
  const params = useParams();
  if (!params.taip) return <FeedPage t="nostr" />;
  // if (params.taip === "urbit") return <FeedPage t={"urbit"} />;
  if (params.taip === "following") return <FeedPage t={"following"} />;
  if (params.taip === "nostr") return <FeedPage t={"nostr"} />;
  // else if (param === FeedType.Rumors) return <Rumors />;
  // else if (param === FeedType.Home) return <UserFeed p={our} />;
  else return <ErrorPage msg="No such page" />;
}
function FeedPage({ t }: { t: FeedType }) {
  const [active, setActive] = useState<FeedType>(t);
  return (
    <>
      <div id="top-tabs">
        <div
          className={active === "urbit" ? "active" : ""}
          onClick={() => setActive("urbit")}
        >
          Urbit
        </div>
        <div
          className={active === "following" ? "active" : ""}
          onClick={() => setActive("following")}
        >
          Following
        </div>
        <div
          className={active === "nostr" ? "active" : ""}
          onClick={() => setActive("nostr")}
        >
          Nostr
        </div>
      </div>
      <div id="feed-proper">
        <Composer />
        {active === "urbit" ? (
          <Urbit />
        ) : active === "following" ? (
          <Following />
        ) : active === "nostr" ? (
          <NostrFeed />
        ) : null}
      </div>
    </>
  );
}

function Urbit() {
  const following = useLocalState((s) => s.following);
  const feed = disaggregate(following, "urbit");
  return (
    <div>
      <PostList data={feed} refetch={() => {}} />
    </div>
  );
}
function Following() {
  const following = useLocalState((s) => s.following);
  const feed = consolidateFeeds(following);
  return (
    <div>
      <PostList data={feed} refetch={() => {}} />
    </div>
  );
}

export default Loader;
// TODO
type MixFeed = any;

function Inner({ data, refetch }: { data: MixFeed; refetch: Function }) {
  return <PostList data={data.mix.fc} refetch={refetch} />;
}