mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-22 12:41:31 +10:00
release: v4.1.0
This commit is contained in:
@ -2,19 +2,21 @@ import { UserDto } from "@reactive-resume/dto";
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
|
||||
interface AuthState {
|
||||
type AuthState = {
|
||||
user: UserDto | null;
|
||||
}
|
||||
};
|
||||
|
||||
interface AuthActions {
|
||||
type AuthActions = {
|
||||
setUser: (user: UserDto | null) => void;
|
||||
}
|
||||
};
|
||||
|
||||
export const useAuthStore = create<AuthState & AuthActions>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
user: null,
|
||||
setUser: (user) => set({ user }),
|
||||
setUser: (user) => {
|
||||
set({ user });
|
||||
},
|
||||
}),
|
||||
{ name: "auth" },
|
||||
),
|
||||
|
||||
@ -17,7 +17,7 @@ type Panel = {
|
||||
handle: PanelHandle;
|
||||
};
|
||||
|
||||
interface BuilderState {
|
||||
type BuilderState = {
|
||||
frame: {
|
||||
ref: HTMLIFrameElement | null;
|
||||
setRef: (ref: HTMLIFrameElement | null) => void;
|
||||
@ -30,11 +30,11 @@ interface BuilderState {
|
||||
left: Panel;
|
||||
right: Panel;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
interface BuilderActions {
|
||||
type BuilderActions = {
|
||||
toggle: (side: "left" | "right") => void;
|
||||
}
|
||||
};
|
||||
|
||||
export const useBuilderStore = create<BuilderState & BuilderActions>()(
|
||||
immer((set) => ({
|
||||
|
||||
@ -16,17 +16,19 @@ type Dialog<T = unknown> = {
|
||||
payload?: DialogPayload<T>;
|
||||
};
|
||||
|
||||
interface DialogState {
|
||||
type DialogState = {
|
||||
dialog: Dialog | null;
|
||||
}
|
||||
};
|
||||
|
||||
interface DialogActions {
|
||||
type DialogActions = {
|
||||
setDialog: <T>(dialog: Dialog<T> | null) => void;
|
||||
}
|
||||
};
|
||||
|
||||
export const useDialogStore = create<DialogState & DialogActions>()((set) => ({
|
||||
dialog: null,
|
||||
setDialog: (dialog) => set({ dialog }),
|
||||
setDialog: (dialog) => {
|
||||
set({ dialog });
|
||||
},
|
||||
}));
|
||||
|
||||
export const useDialog = <T = unknown>(name: DialogName) => {
|
||||
@ -39,8 +41,11 @@ export const useDialog = <T = unknown>(name: DialogName) => {
|
||||
isOpen: !!dialog,
|
||||
mode: dialog?.mode,
|
||||
payload: dialog?.payload as DialogPayload<T>,
|
||||
open: (mode: DialogMode, payload?: DialogPayload<T>) =>
|
||||
useDialogStore.setState({ dialog: { name, mode, payload } }),
|
||||
close: () => useDialogStore.setState({ dialog: null }),
|
||||
open: (mode: DialogMode, payload?: DialogPayload<T>) => {
|
||||
useDialogStore.setState({ dialog: { name, mode, payload } });
|
||||
},
|
||||
close: () => {
|
||||
useDialogStore.setState({ dialog: null });
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,16 +1,18 @@
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
|
||||
interface OpenAIStore {
|
||||
type OpenAIStore = {
|
||||
apiKey: string | null;
|
||||
setApiKey: (apiKey: string | null) => void;
|
||||
}
|
||||
};
|
||||
|
||||
export const useOpenAiStore = create<OpenAIStore>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
apiKey: null,
|
||||
setApiKey: (apiKey) => set({ apiKey }),
|
||||
setApiKey: (apiKey) => {
|
||||
set({ apiKey });
|
||||
},
|
||||
}),
|
||||
{ name: "openai" },
|
||||
),
|
||||
|
||||
@ -35,7 +35,7 @@ export const useResumeStore = create<ResumeStore>()(
|
||||
state.resume.data = _set(state.resume.data, path, value);
|
||||
}
|
||||
|
||||
debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
||||
void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
||||
});
|
||||
},
|
||||
addSection: () => {
|
||||
@ -51,7 +51,7 @@ export const useResumeStore = create<ResumeStore>()(
|
||||
state.resume.data.metadata.layout[lastPageIndex][0].push(`custom.${section.id}`);
|
||||
state.resume.data = _set(state.resume.data, `sections.custom.${section.id}`, section);
|
||||
|
||||
debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
||||
void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
||||
});
|
||||
},
|
||||
removeSection: (sectionId: SectionKey) => {
|
||||
@ -60,9 +60,10 @@ export const useResumeStore = create<ResumeStore>()(
|
||||
|
||||
set((state) => {
|
||||
removeItemInLayout(sectionId, state.resume.data.metadata.layout);
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete state.resume.data.sections.custom[id];
|
||||
|
||||
debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
||||
void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user