blob: a3d223485bca5f99eaf88bacdff4bec8587ecf41 (
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 { useParams } from "wouter";
import useLocalState from "@/state/state";
import { ErrorPage } from "@/pages/Error";
import "@/styles/trill.css";
import "@/styles/feed.css";
import { stringToUser } from "@/logic/nostrill";
import TrillThread from "@/components/trill/Thread";
import NostrThread from "@/components/nostr/Thread";
import { decodeNostrKey } from "@/logic/nostr";
export default function ThreadLoader() {
const { profiles, following } = useLocalState((s) => ({
profiles: s.profiles,
following: s.following,
}));
const params = useParams<{ host: string; id: string }>();
const { host, id } = params;
const uuser = stringToUser(host);
if ("error" in uuser) return <ErrorPage msg={uuser.error} />;
const feed = following.get(host);
const profile = profiles.get(host);
if ("urbit" in uuser.ok)
return (
<TrillThread
feed={feed}
profile={profile}
host={uuser.ok.urbit}
id={id}
/>
);
if ("nostr" in uuser.ok)
return (
<NostrThread
feed={feed}
profile={profile}
host={uuser.ok.nostr}
id={id}
/>
);
else return <ErrorPage msg="weird" />;
}
export function NostrThreadLoader() {
const params = useParams<{ id: string }>();
const { id } = params;
if (!id) return <ErrorPage msg="No thread id passed" />;
const dec = decodeNostrKey(id);
if (!dec) return <ErrorPage msg="Unknown thread id format" />;
return <NostrThread id={dec} host="" />;
}
|