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";
|
import { User } from "@/types/proto/api/v2/user_service";
|
||||||
|
|
||||||
const useCurrentUser = () => {
|
const useCurrentUser = () => {
|
||||||
const userV1Store = useUserV1Store();
|
const userStore = useUserStore();
|
||||||
return userV1Store.currentUser as User;
|
return userStore.currentUser as User;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useCurrentUser;
|
export default useCurrentUser;
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
import { combine } from "zustand/middleware";
|
||||||
import { inboxServiceClient } from "@/grpcweb";
|
import { inboxServiceClient } from "@/grpcweb";
|
||||||
import { Inbox } from "@/types/proto/api/v2/inbox_service";
|
import { Inbox } from "@/types/proto/api/v2/inbox_service";
|
||||||
|
|
||||||
interface InboxStore {
|
interface State {
|
||||||
inboxes: Inbox[];
|
inboxes: Inbox[];
|
||||||
fetchInboxes: () => Promise<Inbox[]>;
|
|
||||||
updateInbox: (inbox: Partial<Inbox>, updateMask: string[]) => Promise<Inbox>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useInboxStore = create<InboxStore>()((set, get) => ({
|
const getDefaultState = (): State => ({
|
||||||
inboxes: [],
|
inboxes: [],
|
||||||
fetchInboxes: async () => {
|
});
|
||||||
const { inboxes } = await inboxServiceClient.listInboxes({});
|
|
||||||
set({ inboxes });
|
export const useInboxStore = create(
|
||||||
return inboxes;
|
combine(getDefaultState(), (set, get) => ({
|
||||||
},
|
fetchInboxes: async () => {
|
||||||
updateInbox: async (inbox: Partial<Inbox>, updateMask: string[]) => {
|
const { inboxes } = await inboxServiceClient.listInboxes({});
|
||||||
const { inbox: updatedInbox } = await inboxServiceClient.updateInbox({
|
set({ inboxes });
|
||||||
inbox,
|
return inboxes;
|
||||||
updateMask,
|
},
|
||||||
});
|
updateInbox: async (inbox: Partial<Inbox>, updateMask: string[]) => {
|
||||||
if (!updatedInbox) {
|
const { inbox: updatedInbox } = await inboxServiceClient.updateInbox({
|
||||||
throw new Error("Inbox not found");
|
inbox,
|
||||||
}
|
updateMask,
|
||||||
const inboxes = get().inboxes;
|
});
|
||||||
set({ inboxes: inboxes.map((i) => (i.name === updatedInbox.name ? updatedInbox : i)) });
|
if (!updatedInbox) {
|
||||||
return 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