summaryrefslogtreecommitdiff
path: root/front/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'front/src/pages')
-rw-r--r--front/src/pages/Feed.tsx104
-rw-r--r--front/src/pages/Settings.tsx92
-rw-r--r--front/src/pages/User.tsx18
3 files changed, 214 insertions, 0 deletions
diff --git a/front/src/pages/Feed.tsx b/front/src/pages/Feed.tsx
new file mode 100644
index 0000000..e29033e
--- /dev/null
+++ b/front/src/pages/Feed.tsx
@@ -0,0 +1,104 @@
+// import spinner from "@/assets/icons/spinner.svg";
+import "@/styles/trill.css";
+import UserFeed from "./User";
+import PostList from "@/components/feed/PostList";
+import useLocalState from "@/state/state";
+import { useParams, useLocation } from "wouter";
+import spinner from "@/assets/triangles.svg";
+import { useState } from "react";
+import Composer from "@/components/feed/Composer";
+// import UserFeed from "./User";
+import { P404 } from "@/Router";
+import { useQuery } from "@tanstack/react-query";
+import { isValidPatp } from "urbit-ob";
+import { eventsToFc } from "@/logic/nostril";
+
+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 { relays } = useLocalState();
+ const feed = eventsToFc(relays);
+ console.log({ feed });
+ const refetch = () => feed;
+ return <PostList data={feed} refetch={refetch} />;
+}
+
+export default Loader;
+// TODO
+type MixFeed = any;
+
+function Inner({ data, refetch }: { data: MixFeed; refetch: Function }) {
+ return <PostList data={data.mix.fc} refetch={refetch} />;
+}
diff --git a/front/src/pages/Settings.tsx b/front/src/pages/Settings.tsx
new file mode 100644
index 0000000..e0f1da9
--- /dev/null
+++ b/front/src/pages/Settings.tsx
@@ -0,0 +1,92 @@
+import useLocalState from "@/state/state";
+import type { UserProfile } from "@/types/nostril";
+import { useState } from "react";
+
+function Settings() {
+ const { UISettings, keys, profiles, relays, api } = useLocalState();
+ const [newRelay, setNewRelay] = useState("");
+ async function saveSetting(
+ bucket: string,
+ key: string,
+ value: string | boolean | number | string[],
+ ) {
+ const json = {
+ "put-entry": {
+ desk: "trill",
+ "bucket-key": bucket,
+ "entry-key": key,
+ value,
+ },
+ };
+ // const res = await poke("settings", "settings-event", json);
+ // if (res) refetchSettings();
+ }
+ async function removeRelay(url: string) {
+ console.log({ url });
+ }
+ async function addNewRelay() {
+ //
+ // await addnr(newRelay);
+ }
+ async function removeProfile(pubkey: string) {
+ api!.removeKey(pubkey);
+ }
+ async function createProfile() {
+ //
+ api!.createKey();
+ }
+
+ return (
+ <div id="settings">
+ <h1>Settings</h1>
+ <div className="setting">
+ <label>Pubkeys</label>
+ {keys.map((k) => {
+ const profile = profiles.get(k);
+ const profileDiv = !profile ? (
+ <div className="profile">
+ <div>Pubkey: {k}</div>
+ <p>No profile set</p>)
+ </div>
+ ) : (
+ <div className="profile">
+ {profile.picture && <img src={profile.picture} />}
+ <div>Name: {profile.name}</div>
+ <div>Pubkey: {k}</div>
+ <div>About: {profile.about}</div>
+ <button onClick={() => removeProfile(k)}>x</button>
+ </div>
+ );
+ return (
+ <div className="options flex" key={k}>
+ {profileDiv}
+ </div>
+ );
+ })}
+ <div className="options flex">
+ <button onClick={createProfile}>Create New</button>
+ </div>
+ </div>
+ <div className="setting">
+ <label>Nostr Relays</label>
+ {Object.keys(relays).map((r) => (
+ // TODO: add connect button to connect and disc to relay one by one
+ <div className="options flex" key={r}>
+ <div>{r}</div>
+ <button onClick={() => removeRelay(r)}>x</button>
+ </div>
+ ))}
+ <div className="options flex">
+ <label>Add new</label>
+ <input
+ type="text"
+ value={newRelay}
+ onChange={(e) => setNewRelay(e.target.value)}
+ />
+ <button onClick={addNewRelay}>Add</button>
+ </div>
+ </div>
+ </div>
+ );
+}
+export default Settings;
diff --git a/front/src/pages/User.tsx b/front/src/pages/User.tsx
new file mode 100644
index 0000000..fc727e4
--- /dev/null
+++ b/front/src/pages/User.tsx
@@ -0,0 +1,18 @@
+// import spinner from "@/assets/icons/spinner.svg";
+import PostList from "@/components/feed/PostList";
+import useLocalState from "@/state/state";
+import type { Ship } from "@/types/urbit";
+
+function UserFeed({ p }: { p: Ship }) {
+ const { api, following } = useLocalState();
+ const feed = following.get(api!.airlock.our!);
+ const refetch = () => feed;
+ if (p === api!.airlock.our)
+ return (
+ <div id="feed-proper">
+ <PostList data={feed!} refetch={refetch} />
+ </div>
+ );
+}
+
+export default UserFeed;