summaryrefslogtreecommitdiff
path: root/front/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'front/src/state')
-rw-r--r--front/src/state/state.ts47
1 files changed, 32 insertions, 15 deletions
diff --git a/front/src/state/state.ts b/front/src/state/state.ts
index 28f3fb2..01b8ea1 100644
--- a/front/src/state/state.ts
+++ b/front/src/state/state.ts
@@ -1,11 +1,11 @@
import type { JSX } from "react";
import { start } from "@/logic/api";
-import IO from "@/logic/requests/nostril";
+import IO from "@/logic/requests/nostrill";
import type { ComposerData } from "@/types/ui";
import { create } from "zustand";
-import type { UserProfile } from "@/types/nostril";
+import type { UserProfile } from "@/types/nostrill";
import type { Event } from "@/types/nostr";
-import type { FC } from "@/types/trill";
+import type { FC, Poast } from "@/types/trill";
// TODO handle airlock connection issues
// the SSE pipeline has a "status-update" event FWIW
// type AirlockState = "connecting" | "connected" | "failed";
@@ -18,7 +18,8 @@ export type LocalState = {
setModal: (modal: JSX.Element | null) => void;
composerData: ComposerData | null;
setComposerData: (c: ComposerData | null) => void;
- keys: string[];
+ key: string;
+ nostrFeed: Event[];
relays: Record<string, Event[]>;
profiles: Map<string, UserProfile>; // pubkey key
following: Map<string, FC>;
@@ -26,7 +27,7 @@ export type LocalState = {
};
const creator = create<LocalState>();
-const useLocalState = creator((set, _get) => ({
+const useLocalState = creator((set, get) => ({
isNew: false,
api: null,
init: async () => {
@@ -35,22 +36,38 @@ const useLocalState = creator((set, _get) => ({
console.log({ api });
await api.subscribeStore((data) => {
console.log("store sub", data);
- const { feed, following, relays, profiles, keys } = data;
+ if ("state" in data) {
+ const { feed, nostr, following, relays, profiles, key } = data.state;
+ const flwing = new Map(Object.entries(following as Record<string, FC>));
+ flwing.set(api!.airlock.our!, feed);
+ set({
+ relays,
+ nostrFeed: nostr,
+ profiles: new Map(Object.entries(profiles)),
+ following: flwing,
+ key,
+ });
+ } else if ("fact" in data) {
+ if ("post" in data.fact) {
+ if ("add" in data.fact.post) {
+ const post: Poast = data.fact.post.add.post;
+ const following = get().following;
+ const curr = following.get(post.author);
+ const fc = curr ? curr : { feed: {}, start: null, end: null };
+ fc.feed[post.id] = post;
+ following.set(post.author, fc);
- const flwing = new Map(Object.entries(following as Record<string, FC>));
- flwing.set(api!.airlock.our!, feed);
- set({
- relays,
- profiles: new Map(Object.entries(profiles)),
- following: flwing,
- keys,
- });
+ set({ following });
+ }
+ }
+ }
});
set({ api });
},
- keys: [],
+ key: "",
profiles: new Map(),
relays: {},
+ nostrFeed: [],
following: new Map(),
followers: [],
UISettings: {},