diff --git a/apps/mobile/src/store/inbox/hooks.ts b/apps/mobile/src/store/inbox/hooks.ts new file mode 100644 index 000000000..5af370036 --- /dev/null +++ b/apps/mobile/src/store/inbox/hooks.ts @@ -0,0 +1,7 @@ +import { useInboxStore } from "./store" + +export const useInbox = (inboxId: string) => { + return useInboxStore((state) => { + return state.inboxes[inboxId] + }) +} diff --git a/apps/mobile/src/store/inbox/store.ts b/apps/mobile/src/store/inbox/store.ts index a344a7865..bcd77310f 100644 --- a/apps/mobile/src/store/inbox/store.ts +++ b/apps/mobile/src/store/inbox/store.ts @@ -3,19 +3,27 @@ import { InboxService } from "@/src/services/inbox" import { createTransaction, createZustandStore } from "../internal/helper" -const defaultState = { - inboxes: [], +interface InboxState { + inboxes: Record } -export const useInboxStore = createZustandStore<{ - inboxes: InboxSchema[] -}>("inbox")(() => defaultState) + +const defaultState = { + inboxes: {}, +} + +export const useInboxStore = createZustandStore("inbox")(() => defaultState) // const get = useInboxStore.getState const set = useInboxStore.setState class InboxActions { async upsertManyInSession(inboxes: InboxSchema[]) { const state = useInboxStore.getState() - const nextInboxes = [...state.inboxes, ...inboxes] + const nextInboxes: InboxState["inboxes"] = { + ...state.inboxes, + } + inboxes.forEach((inbox) => { + nextInboxes[inbox.id] = inbox + }) set({ ...state, inboxes: nextInboxes,