This commit is contained in:
Timothy Jaeryang Baek
2026-05-09 07:11:17 +09:00
parent 5b80932e59
commit a938c8ae2e

View File

@@ -184,6 +184,12 @@
navigateHandler();
}
let saveControlsTimer;
$: if (!loading && !$temporaryChatEnabled && $chatId && params && chatFiles) {
clearTimeout(saveControlsTimer);
saveControlsTimer = setTimeout(saveControls, 400);
}
const navigateHandler = async () => {
// Mark the outgoing chat as read before loading the new one.
// $chatId still holds the previous chat here — loadChat() updates it.
@@ -191,6 +197,8 @@
updateLastReadAt($chatId);
}
clearTimeout(saveControlsTimer);
await saveControls();
loading = true;
prompt = '';
@@ -811,6 +819,8 @@
return () => {
try {
clearTimeout(saveControlsTimer);
saveControls();
if (chatIdProp && !$temporaryChatEnabled) {
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;
let saveDraftTimeout: ReturnType<typeof setTimeout> | null = null;