mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: sync record
This commit is contained in:
26
src/hooks/useChatModel.ts
vendored
26
src/hooks/useChatModel.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { clone } from 'lodash';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
|
||||
@@ -6,7 +6,7 @@ import { CHAT_MODEL_JSON, readJSON, writeJSON } from '@/utils';
|
||||
import useInit from '@/hooks/useInit';
|
||||
|
||||
export default function useChatModel(key: string, file = CHAT_MODEL_JSON) {
|
||||
const [modelJson, setModelJson] = useState<Record<string, any>>({});
|
||||
const [modelJson, setModelJson] = useState<Record<string, any>>([]);
|
||||
|
||||
useInit(async () => {
|
||||
const data = await readJSON(file, {
|
||||
@@ -23,5 +23,25 @@ export default function useChatModel(key: string, file = CHAT_MODEL_JSON) {
|
||||
setModelJson(oData);
|
||||
}
|
||||
|
||||
return { modelJson, modelSet, modelData: modelJson?.[key] || [] }
|
||||
return { modelJson, modelSet, modelData: modelJson?.[key] || [] };
|
||||
}
|
||||
|
||||
export function useCacheModel(file: string) {
|
||||
const [modelJson, setModelJson] = useState<Record<string, any>[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!file) return;
|
||||
(async () => {
|
||||
const data = await readJSON(file, { isRoot: true });
|
||||
setModelJson(data);
|
||||
})();
|
||||
}, [file]);
|
||||
|
||||
const modelSet = async (data: Record<string, any>[]) => {
|
||||
await writeJSON(file, data, { isRoot: true });
|
||||
await invoke('window_reload', { label: 'core' });
|
||||
setModelJson(data);
|
||||
}
|
||||
|
||||
return { modelJson, modelSet };
|
||||
}
|
||||
Reference in New Issue
Block a user