Skip to content

Commit 0a90ab9

Browse files
committed
fix: fix auto select table model
1 parent e91aaf9 commit 0a90ab9

File tree

1 file changed

+19
-21
lines changed
  • chat2db-client/src/components/Console

1 file changed

+19
-21
lines changed

chat2db-client/src/components/Console/index.tsx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
133133
editorRef: editorRef?.current,
134134
}));
135135

136-
useEffect(() => {}, []);
137-
138136
useEffect(() => {
139137
if (source !== 'workspace') {
140138
return;
@@ -151,20 +149,20 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
151149
} else {
152150
// 活跃时自动保存
153151
indexedDB
154-
.getDataByCursor('chat2db', 'workspaceConsoleDDL', {
155-
consoleId: executeParams.consoleId!,
156-
userId: getCookie('CHAT2DB.USER_ID'),
157-
})
158-
.then((res: any) => {
159-
const value = defaultValue || res?.[0]?.ddl || '';
160-
const oldValue = editorRef?.current?.getAllContent();
161-
if(value !== oldValue){
162-
editorRef?.current?.setValue(value, 'reset');
163-
}
164-
setTimeout(() => {
165-
timingAutoSave();
166-
}, 0);
167-
});
152+
.getDataByCursor('chat2db', 'workspaceConsoleDDL', {
153+
consoleId: executeParams.consoleId!,
154+
userId: getCookie('CHAT2DB.USER_ID'),
155+
})
156+
.then((res: any) => {
157+
const value = defaultValue || res?.[0]?.ddl || '';
158+
const oldValue = editorRef?.current?.getAllContent();
159+
if (value !== oldValue) {
160+
editorRef?.current?.setValue(value, 'reset');
161+
}
162+
setTimeout(() => {
163+
timingAutoSave();
164+
}, 0);
165+
});
168166
}
169167
return () => {
170168
if (timerRef.current) {
@@ -175,13 +173,13 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
175173

176174
function timingAutoSave() {
177175
timerRef.current = setInterval(() => {
178-
if(executeParams.status === ConsoleStatus.RELEASE){
176+
if (executeParams.status === ConsoleStatus.RELEASE) {
179177
const p: any = {
180178
id: executeParams.consoleId,
181179
ddl: editorRef?.current?.getAllContent(),
182180
};
183-
historyServer.updateSavedConsole(p)
184-
}else{
181+
historyServer.updateSavedConsole(p);
182+
} else {
185183
indexedDB.updateData('chat2db', 'workspaceConsoleDDL', {
186184
consoleId: executeParams.consoleId!,
187185
ddl: editorRef?.current?.getAllContent(),
@@ -455,10 +453,10 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
455453
};
456454

457455
const handleSelectTableSyncModel = () => {
458-
const syncModel: SyncModelType | null = Number(localStorage.getItem('syncTableModel')) ?? null;
456+
const syncModel = localStorage.getItem('syncTableModel');
459457
const hasAiAccess = aiModel.hasWhite;
460458
if (syncModel !== null) {
461-
setSyncTableModel(syncModel);
459+
setSyncTableModel(Number(syncModel));
462460
return;
463461
}
464462

0 commit comments

Comments
 (0)