File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 175175 let chatFiles = [];
176176 let files = [];
177177 let params = {};
178+ let oldParams = {};
179+ let oldChatFiles = [];
180+ let controlsSaveTimer: ReturnType <typeof setTimeout > | null = null ;
181+
182+ $ : if (! equal (params , oldParams ) || ! equal (chatFiles , oldChatFiles )) {
183+ oldParams = structuredClone (params );
184+ oldChatFiles = structuredClone (chatFiles );
185+ if (! loading && ! $temporaryChatEnabled && $chatId ) {
186+ clearTimeout (controlsSaveTimer );
187+ controlsSaveTimer = setTimeout (() => {
188+ controlsSaveTimer = null ;
189+ saveControlsHandler ().catch ((err ) => console .error (' [saveControlsHandler]' , err ));
190+ }, 400 );
191+ }
192+ }
178193
179194 $ : if (chatIdProp ) {
180195 navigateHandler ();
187202 updateLastReadAt ($chatId );
188203 }
189204
205+ clearTimeout (controlsSaveTimer );
206+ controlsSaveTimer = null ;
207+
190208 loading = true ;
191209
192210 prompt = ' ' ;
824842
825843 return () => {
826844 try {
845+ clearTimeout (controlsSaveTimer );
827846 if (chatIdProp && ! $temporaryChatEnabled ) {
828847 updateLastReadAt (chatIdProp );
829848 }
27232742 return _chatId ;
27242743 };
27252744
2745+ const saveControlsHandler = async () => {
2746+ const _chatId = $chatId ;
2747+ if (! _chatId || $temporaryChatEnabled || loading ) return ;
2748+ await updateChatById (localStorage .token , _chatId , {
2749+ params: params ,
2750+ files: chatFiles
2751+ });
2752+ };
2753+
27262754 const saveChatHandler = async (_chatId , history ) => {
27272755 if ($chatId == _chatId ) {
27282756 if (! $temporaryChatEnabled ) {
You can’t perform that action at this time.
0 commit comments