From a938c8ae2e45a00d2f06151fdaeaee94e54a8095 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 9 May 2026 07:11:17 +0900 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index d469c58729..be5feab935 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -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 | null = null;