mirror of
https://litchi.icu/ngc2207/judge.git
synced 2025-05-18 20:46:34 +00:00
feat(store): add useCodeEditorStore for managing code editor state
chore(types): define CodeEditorState interface
This commit is contained in:
parent
7c90efc02a
commit
262fea4938
@ -24,7 +24,8 @@
|
||||
"react": "19.0.0-rc-66855b96-20241106",
|
||||
"react-dom": "19.0.0-rc-66855b96-20241106",
|
||||
"tailwind-merge": "^2.6.0",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"zustand": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20",
|
||||
|
17
src/store/useCodeEditorStore.ts
Normal file
17
src/store/useCodeEditorStore.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { create } from "zustand";
|
||||
import { CodeEditorState } from "@/types";
|
||||
import { DEFAULT_LANGUAGE } from "@/constants/languages";
|
||||
import { persist, createJSONStorage } from "zustand/middleware";
|
||||
|
||||
export const useCodeEditorStore = create<CodeEditorState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
language: DEFAULT_LANGUAGE,
|
||||
setLanguage: (language: string) => set({ language }),
|
||||
}),
|
||||
{
|
||||
name: "language-storage",
|
||||
storage: createJSONStorage(() => localStorage),
|
||||
}
|
||||
)
|
||||
);
|
5
src/types/index.ts
Normal file
5
src/types/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface CodeEditorState {
|
||||
language: string;
|
||||
|
||||
setLanguage: (language: string) => void;
|
||||
}
|
Loading…
Reference in New Issue
Block a user