feat(store): add useCodeEditorStore for managing code editor state

chore(types): define CodeEditorState interface
This commit is contained in:
ngc2207 2024-12-31 20:22:33 +08:00
parent 7c90efc02a
commit 262fea4938
3 changed files with 24 additions and 1 deletions

View File

@ -24,7 +24,8 @@
"react": "19.0.0-rc-66855b96-20241106", "react": "19.0.0-rc-66855b96-20241106",
"react-dom": "19.0.0-rc-66855b96-20241106", "react-dom": "19.0.0-rc-66855b96-20241106",
"tailwind-merge": "^2.6.0", "tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7" "tailwindcss-animate": "^1.0.7",
"zustand": "^5.0.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20", "@types/node": "^20",

View 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
View File

@ -0,0 +1,5 @@
export interface CodeEditorState {
language: string;
setLanguage: (language: string) => void;
}