feat(store): add problem editor state management with zustand

This commit is contained in:
cfngc4594 2025-03-19 15:13:34 +08:00
parent 154b66d524
commit 71227b0890

View File

@ -0,0 +1,26 @@
import { create } from "zustand";
import { EditorLanguage } from "@prisma/client";
import { createJSONStorage, persist } from "zustand/middleware";
import { DEFAULT_EDITOR_LANGUAGE } from "@/config/editor-language";
/**
* State management for problem editor settings.
*/
interface ProblemEditorState {
globalEditorLanguage: EditorLanguage;
setGlobalEditorLanguage: (language: EditorLanguage) => void;
}
export const useProblemEditorStore = create<ProblemEditorState>()(
persist(
(set) => ({
globalEditorLanguage: DEFAULT_EDITOR_LANGUAGE,
setGlobalEditorLanguage: (language) => set({ globalEditorLanguage: language }),
}),
{
name: "problem-editor",
storage: createJSONStorage(() => localStorage),
partialize: (state) => ({ globalEditorLanguage: state.globalEditorLanguage }),
}
)
);