mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
feat(store): add problem editor state management with zustand
This commit is contained in:
parent
154b66d524
commit
71227b0890
26
src/store/useProblemEditorStore.ts
Normal file
26
src/store/useProblemEditorStore.ts
Normal 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 }),
|
||||
}
|
||||
)
|
||||
);
|
Loading…
Reference in New Issue
Block a user