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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
// import spinner from "@/assets/icons/spinner.svg";
import "@/styles/trill.css";
import "@/styles/feed.css";
import UserFeed from "./User";
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 Icon from "@/components/Icon";
import toast from "react-hot-toast";
// import UserFeed from "./User";
import { P404 } from "@/Router";
import { isValidPatp } from "urbit-ob";
import { eventsToFc } from "@/logic/nostrill";
type FeedType = "global" | "following" | "nostr";
function Loader() {
// const { api } = useLocalState();
const params = useParams();
console.log({ params });
// const [loc, navigate] = useLocation();
// console.log({ loc });
// const our = api!.airlock.ship;
if (params.taip === "global") return <FeedPage t={"global"} />;
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 if (isValidPatp(params.taip!)) return <UserFeed p={params.taip!} />;
else return <P404 />;
}
function FeedPage({ t }: { t: FeedType }) {
const [active, setActive] = useState<FeedType>(t);
return (
<main>
<div id="top-tabs">
<div
className={active === "global" ? "active" : ""}
onClick={() => setActive("global")}
>
Global
</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 === "global" ? (
<Global />
) : active === "following" ? (
<Global />
) : active === "nostr" ? (
<Nostr />
) : null}
</div>
</main>
);
}
// {active === "global" ? (
// <Global />
// ) : active === "following" ? (
// <Global />
// ) : (
// <Global />
// )}
function Global() {
// const { api } = useLocalState();
// const { isPending, data, refetch } = useQuery({
// queryKey: ["globalFeed"],
// queryFn: () => {
// return api!.scryFeed(null, null);
// },
// });
// console.log(data, "scry feed data");
// if (isPending) return <img className="x-center" src={spinner} />;
// else if ("bucun" in data) return <p>Error</p>;
// else return <Inner data={data} refetch={refetch} />;
return <p>Error</p>;
}
function Nostr() {
const { nostrFeed, api } = useLocalState((s) => ({
nostrFeed: s.nostrFeed,
api: s.api,
}));
const [isSyncing, setIsSyncing] = useState(false);
const feed = eventsToFc(nostrFeed);
console.log({ feed });
const refetch = () => feed;
const handleResync = async () => {
if (!api) return;
setIsSyncing(true);
try {
await api.syncRelays();
toast.success("Nostr feed sync initiated");
} catch (error) {
toast.error("Failed to sync Nostr feed");
console.error("Sync error:", error);
} finally {
setIsSyncing(false);
}
};
// Show empty state with resync option when no feed data
if (!feed || !feed.feed || Object.keys(feed.feed).length === 0) {
return (
<div className="nostr-empty-state">
<div className="empty-content">
<Icon name="nostr" size={48} color="textMuted" />
<h3>No Nostr Posts</h3>
<p>
Your Nostr feed appears to be empty. Try syncing with your relays to
fetch the latest posts.
</p>
<button
onClick={handleResync}
disabled={isSyncing}
className="resync-btn"
>
{isSyncing ? (
<>
<img src={spinner} alt="Loading" className="btn-spinner" />
Syncing...
</>
) : (
<>
<Icon name="settings" size={16} />
Sync Relays
</>
)}
</button>
</div>
</div>
);
}
// Show feed with resync button in header
return (
<div className="nostr-feed">
<div className="nostr-header">
<div className="feed-info">
<h4>Nostr Feed</h4>
<span className="post-count">
{Object.keys(feed.feed).length} posts
</span>
</div>
<button
onClick={handleResync}
disabled={isSyncing}
className="resync-btn-small"
title="Sync with Nostr relays"
>
{isSyncing ? (
<img src={spinner} alt="Loading" className="btn-spinner-small" />
) : (
<Icon name="settings" size={16} />
)}
</button>
</div>
<PostList data={feed} refetch={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} />;
}
|