wip: migrate to zustand
This commit is contained in:
13
src/stores/accounts.tsx
Normal file
13
src/stores/accounts.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { getActiveAccount } from "@utils/storage";
|
||||
import { create } from "zustand";
|
||||
|
||||
export const useActiveAccount = create((set) => ({
|
||||
account: null,
|
||||
fetch: async () => {
|
||||
const response = await getActiveAccount();
|
||||
set({ account: response });
|
||||
},
|
||||
updateFollows: (list: any) => {
|
||||
set((state: any) => ({ account: { ...state.account, follows: list } }));
|
||||
},
|
||||
}));
|
||||
17
src/stores/channels.tsx
Normal file
17
src/stores/channels.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { getChannels } from "@utils/storage";
|
||||
import { create } from "zustand";
|
||||
|
||||
export const useChannels = create((set) => ({
|
||||
channels: [],
|
||||
fetch: async () => {
|
||||
const response = await getChannels(10, 0);
|
||||
set({ channels: response });
|
||||
},
|
||||
}));
|
||||
|
||||
export const useChannelMessage = create((set) => ({
|
||||
messages: [],
|
||||
add: (message: any) => {
|
||||
set((state: any) => ({ messages: [...state.messages, message] }));
|
||||
},
|
||||
}));
|
||||
21
src/stores/chats.tsx
Normal file
21
src/stores/chats.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { getChatMessages, getChatsByPubkey } from "@utils/storage";
|
||||
import { create } from "zustand";
|
||||
|
||||
export const useChats = create((set) => ({
|
||||
chats: [],
|
||||
fetch: async (pubkey: string) => {
|
||||
const response = await getChatsByPubkey(pubkey);
|
||||
set({ chats: response });
|
||||
},
|
||||
}));
|
||||
|
||||
export const useChatMessages = create((set) => ({
|
||||
messages: [],
|
||||
fetch: async (receiver_pubkey: string, sender_pubkey: string) => {
|
||||
const response = await getChatMessages(receiver_pubkey, sender_pubkey);
|
||||
set({ messages: response });
|
||||
},
|
||||
add: (message: any) => {
|
||||
set((state: any) => ({ messages: [...state.messages, message] }));
|
||||
},
|
||||
}));
|
||||
@@ -1,3 +0,0 @@
|
||||
import { atom } from "jotai";
|
||||
|
||||
export const composerAtom = atom({ type: "post" });
|
||||
@@ -1,8 +0,0 @@
|
||||
import { atom } from "jotai";
|
||||
import { atomWithReset } from "jotai/utils";
|
||||
|
||||
// note content
|
||||
export const noteContentAtom = atomWithReset("");
|
||||
|
||||
// notify user that connector has receive newer note
|
||||
export const hasNewerNoteAtom = atom(false);
|
||||
@@ -1,8 +0,0 @@
|
||||
import { atom } from "jotai";
|
||||
|
||||
export const onboardingAtom = atom({
|
||||
pubkey: null,
|
||||
privkey: null,
|
||||
metadata: null,
|
||||
follows: null,
|
||||
});
|
||||
Reference in New Issue
Block a user