refac
This commit is contained in:
1 parent
5b80932e59
commit
a938c8ae2e
1 file changed
+17
@@ -184,6 +184,12 @@
|
|||||||
navigateHandler();
|
navigateHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let saveControlsTimer;
|
||||||
|
$: if (!loading && !$temporaryChatEnabled && $chatId && params && chatFiles) {
|
||||||
|
clearTimeout(saveControlsTimer);
|
||||||
|
saveControlsTimer = setTimeout(saveControls, 400);
|
||||||
|
}
|
||||||
|
|
||||||
const navigateHandler = async () => {
|
const navigateHandler = async () => {
|
||||||
// Mark the outgoing chat as read before loading the new one.
|
// Mark the outgoing chat as read before loading the new one.
|
||||||
// $chatId still holds the previous chat here — loadChat() updates it.
|
// $chatId still holds the previous chat here — loadChat() updates it.
|
||||||
@@ -191,6 +197,8 @@
|
|||||||
updateLastReadAt($chatId);
|
updateLastReadAt($chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearTimeout(saveControlsTimer);
|
||||||
|
await saveControls();
|
||||||
loading = true;
|
loading = true;
|
||||||
|
|
||||||
prompt = '';
|
prompt = '';
|
||||||
@@ -811,6 +819,8 @@
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
try {
|
try {
|
||||||
|
clearTimeout(saveControlsTimer);
|
||||||
|
saveControls();
|
||||||
if (chatIdProp && !$temporaryChatEnabled) {
|
if (chatIdProp && !$temporaryChatEnabled) {
|
||||||
updateLastReadAt(chatIdProp);
|
updateLastReadAt(chatIdProp);
|
||||||
}
|
}
|
||||||
@@ -2758,6 +2768,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveControls = async () => {
|
||||||
|
if (!$chatId || $temporaryChatEnabled) return;
|
||||||
|
await updateChatById(localStorage.token, $chatId, { params, files: chatFiles }).catch(
|
||||||
|
(err) => console.error('[controls autosave]', err)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const MAX_DRAFT_LENGTH = 5000;
|
const MAX_DRAFT_LENGTH = 5000;
|
||||||
let saveDraftTimeout: ReturnType<typeof setTimeout> | null = null;
|
let saveDraftTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user