mirror of https://github.com/usememos/memos
chore: remove v1 prefix in store name
parent
df3303dcd3
commit
df5aeb6d88
@ -1,9 +1,9 @@
|
||||
import { useUserV1Store } from "@/store/v1";
|
||||
import { useUserStore } from "@/store/v1";
|
||||
import { User } from "@/types/proto/api/v2/user_service";
|
||||
|
||||
const useCurrentUser = () => {
|
||||
const userV1Store = useUserV1Store();
|
||||
return userV1Store.currentUser as User;
|
||||
const userStore = useUserStore();
|
||||
return userStore.currentUser as User;
|
||||
};
|
||||
|
||||
export default useCurrentUser;
|
||||
|
@ -1,30 +1,34 @@
|
||||
import { create } from "zustand";
|
||||
import { combine } from "zustand/middleware";
|
||||
import { inboxServiceClient } from "@/grpcweb";
|
||||
import { Inbox } from "@/types/proto/api/v2/inbox_service";
|
||||
|
||||
interface InboxStore {
|
||||
interface State {
|
||||
inboxes: Inbox[];
|
||||
fetchInboxes: () => Promise<Inbox[]>;
|
||||
updateInbox: (inbox: Partial<Inbox>, updateMask: string[]) => Promise<Inbox>;
|
||||
}
|
||||
|
||||
export const useInboxStore = create<InboxStore>()((set, get) => ({
|
||||
const getDefaultState = (): State => ({
|
||||
inboxes: [],
|
||||
fetchInboxes: async () => {
|
||||
const { inboxes } = await inboxServiceClient.listInboxes({});
|
||||
set({ inboxes });
|
||||
return inboxes;
|
||||
},
|
||||
updateInbox: async (inbox: Partial<Inbox>, updateMask: string[]) => {
|
||||
const { inbox: updatedInbox } = await inboxServiceClient.updateInbox({
|
||||
inbox,
|
||||
updateMask,
|
||||
});
|
||||
if (!updatedInbox) {
|
||||
throw new Error("Inbox not found");
|
||||
}
|
||||
const inboxes = get().inboxes;
|
||||
set({ inboxes: inboxes.map((i) => (i.name === updatedInbox.name ? updatedInbox : i)) });
|
||||
return updatedInbox;
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
export const useInboxStore = create(
|
||||
combine(getDefaultState(), (set, get) => ({
|
||||
fetchInboxes: async () => {
|
||||
const { inboxes } = await inboxServiceClient.listInboxes({});
|
||||
set({ inboxes });
|
||||
return inboxes;
|
||||
},
|
||||
updateInbox: async (inbox: Partial<Inbox>, updateMask: string[]) => {
|
||||
const { inbox: updatedInbox } = await inboxServiceClient.updateInbox({
|
||||
inbox,
|
||||
updateMask,
|
||||
});
|
||||
if (!updatedInbox) {
|
||||
throw new Error("Inbox not found");
|
||||
}
|
||||
const inboxes = get().inboxes;
|
||||
set({ inboxes: inboxes.map((i) => (i.name === updatedInbox.name ? updatedInbox : i)) });
|
||||
return updatedInbox;
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
Loading…
Reference in New Issue