2024-12-31 12:22:33 +00:00
|
|
|
import { create } from "zustand";
|
|
|
|
import { CodeEditorState } from "@/types";
|
2024-12-31 12:59:04 +00:00
|
|
|
import { DEFAULT_THEME } from "@/constants/themes";
|
2024-12-31 12:22:33 +00:00
|
|
|
import { DEFAULT_LANGUAGE } from "@/constants/languages";
|
|
|
|
import { persist, createJSONStorage } from "zustand/middleware";
|
|
|
|
|
|
|
|
export const useCodeEditorStore = create<CodeEditorState>()(
|
|
|
|
persist(
|
|
|
|
(set, get) => ({
|
|
|
|
language: DEFAULT_LANGUAGE,
|
2024-12-31 12:59:04 +00:00
|
|
|
theme: DEFAULT_THEME,
|
2024-12-31 12:22:33 +00:00
|
|
|
setLanguage: (language: string) => set({ language }),
|
2024-12-31 12:59:04 +00:00
|
|
|
setTheme: (theme: string) => set({ theme }),
|
2024-12-31 12:22:33 +00:00
|
|
|
}),
|
|
|
|
{
|
2024-12-31 12:59:04 +00:00
|
|
|
name: "code-editor-storage",
|
2024-12-31 12:22:33 +00:00
|
|
|
storage: createJSONStorage(() => localStorage),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|