import type { JSX } from "react"; import { start } from "@/logic/api"; import IO from "@/logic/requests/nostril"; import type { ComposerData } from "@/types/ui"; import { create } from "zustand"; import type { UserProfile } from "@/types/nostril"; import type { Event } from "@/types/nostr"; import type { FC } from "@/types/trill"; // TODO handle airlock connection issues // the SSE pipeline has a "status-update" event FWIW // type AirlockState = "connecting" | "connected" | "failed"; export type LocalState = { isNew: boolean; api: IO | null; init: () => Promise; UISettings: Record; modal: JSX.Element | null; setModal: (modal: JSX.Element | null) => void; composerData: ComposerData | null; setComposerData: (c: ComposerData | null) => void; keys: string[]; relays: Record; profiles: Map; // pubkey key following: Map; followers: string[]; }; const creator = create(); const useLocalState = creator((set, _get) => ({ isNew: false, api: null, init: async () => { const airlock = await start(); const api = new IO(airlock); console.log({ api }); await api.subscribeStore((data) => { console.log("store sub", data); const { feed, following, relays, profiles, keys } = data; const flwing = new Map(Object.entries(following as Record)); flwing.set(api!.airlock.our!, feed); set({ relays, profiles: new Map(Object.entries(profiles)), following: flwing, keys, }); }); set({ api }); }, keys: [], profiles: new Map(), relays: {}, following: new Map(), followers: [], UISettings: {}, modal: null, setModal: (modal) => set({ modal }), // composer data composerData: null, setComposerData: (composerData) => set({ composerData }), })); export default useLocalState;