mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-17 23:12:23 +00:00
refactor(store): 重构编辑器配置状态管理
- 移除了 useEditorConfigStore 的实现 - 修改了 resetConfig 的实现,使用 state.defaultConfig 作为默认配置- 重命名 EditorConfigState为 EditorConfigState2
This commit is contained in:
parent
96694604ec
commit
2ca98cccfb
@ -32,31 +32,11 @@ export const useEditorConfigStore = create<EditorConfigState>((set) => {
|
|||||||
resetConfig: () => set((state) => {
|
resetConfig: () => set((state) => {
|
||||||
localStorage.removeItem('editorConfig');
|
localStorage.removeItem('editorConfig');
|
||||||
return { config: state.defaultConfig };
|
return { config: state.defaultConfig };
|
||||||
}),
|
})
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface EditorConfigState {
|
interface EditorConfigState2 {
|
||||||
config: any;
|
config: any;
|
||||||
setConfig: (config: any) => void;
|
setConfig: (config: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useEditorConfigStore = create<EditorConfigState>((set) => {
|
|
||||||
// 从localStorage读取保存的配置
|
|
||||||
let savedConfig = null;
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
savedConfig = localStorage.getItem('editorConfig');
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedConfig = savedConfig ? JSON.parse(savedConfig) : {};
|
|
||||||
|
|
||||||
return {
|
|
||||||
config: parsedConfig,
|
|
||||||
setConfig: (config) => {
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
localStorage.setItem('editorConfig', JSON.stringify(config));
|
|
||||||
}
|
|
||||||
set({ config });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
Loading…
Reference in New Issue
Block a user