Fix last updated sort

This commit is contained in:
Webifi 2023-06-24 16:56:03 -05:00
parent 52affeb83f
commit 83fd00c16e
2 changed files with 15 additions and 5 deletions

View File

@ -18,7 +18,6 @@
const onStateChange = (...args:any) => { const onStateChange = (...args:any) => {
sortOption = getChatSortOption() sortOption = getChatSortOption()
sortedChats = $chatsStorage.sort(sortOption.sortFn) sortedChats = $chatsStorage.sort(sortOption.sortFn)
// console.log('Sorting', sortOption, sortedChats)
} }
$: onStateChange($checkStateChange) $: onStateChange($checkStateChange)
@ -43,8 +42,10 @@
<li><a href={'#'} class="is-disabled">No chats yet...</a></li> <li><a href={'#'} class="is-disabled">No chats yet...</a></li>
{:else} {:else}
{#key $checkStateChange} {#key $checkStateChange}
{#each sortedChats as chat, i} {#each sortedChats as chat, i}
{#key chat.id}
<ChatMenuItem activeChatId={activeChatId} chat={chat} prevChat={sortedChats[i - 1]} nextChat={sortedChats[i + 1]} /> <ChatMenuItem activeChatId={activeChatId} chat={chat} prevChat={sortedChats[i - 1]} nextChat={sortedChats[i + 1]} />
{/key}
{/each} {/each}
{/key} {/key}
{/if} {/if}

View File

@ -242,6 +242,15 @@
currentChatMessages.set(getChat(chatId).messages) currentChatMessages.set(getChat(chatId).messages)
}, 10) }, 10)
} }
const signalChangeTimers: any = {}
const setChatLastUse = (chatId: number, time: number) => {
clearTimeout(signalChangeTimers[chatId])
signalChangeTimers[chatId] = setTimeout(() => {
getChat(chatId).lastUse = time
saveChatStore()
}, 500)
}
const setMessagesTimers: any = {} const setMessagesTimers: any = {}
export const setMessages = (chatId: number, messages: Message[]) => { export const setMessages = (chatId: number, messages: Message[]) => {
@ -253,13 +262,13 @@
setMessagesTimers[chatId] = setTimeout(() => { setMessagesTimers[chatId] = setTimeout(() => {
getChat(chatId).messages = messages getChat(chatId).messages = messages
saveChatStore() saveChatStore()
setChatLastUse(chatId, Date.now())
}, 200) }, 200)
} else { } else {
clearTimeout(setMessagesTimers[chatId]) clearTimeout(setMessagesTimers[chatId])
const chat = getChat(chatId) getChat(chatId).messages = messages
chat.lastUse = Date.now()
chat.messages = messages
saveChatStore() saveChatStore()
setChatLastUse(chatId, Date.now())
} }
} }