chore: sync

This commit is contained in:
lencx
2022-12-23 00:43:58 +08:00
parent 921d670f53
commit 8319eae519
10 changed files with 345 additions and 35 deletions

View File

@@ -5,18 +5,20 @@ import { invoke } from '@tauri-apps/api';
import { CHAT_MODEL_JSON, readJSON, writeJSON } from '@/utils';
import useInit from '@/hooks/useInit';
export default function useChatModel(key: string) {
export default function useChatModel(key: string, file = CHAT_MODEL_JSON) {
const [modelJson, setModelJson] = useState<Record<string, any>>({});
useInit(async () => {
const data = await readJSON(CHAT_MODEL_JSON, { name: 'ChatGPT Model', [key]: [] });
const data = await readJSON(file, {
defaultVal: { name: 'ChatGPT Model', [key]: [] },
});
setModelJson(data);
});
const modelSet = async (data: Record<string, any>[]) => {
const oData = clone(modelJson);
oData[key] = data;
await writeJSON(CHAT_MODEL_JSON, oData);
await writeJSON(file, oData);
await invoke('window_reload', { label: 'core' });
setModelJson(oData);
}