guard against deleting the last chat

This commit is contained in:
Emil Elgaard 2023-03-26 16:59:30 -04:00
parent 8075585778
commit d95152efe2
1 changed files with 3 additions and 2 deletions

View File

@ -8,10 +8,11 @@
$: activeChatId = $params && $params.chatId ? parseInt($params.chatId) : undefined $: activeChatId = $params && $params.chatId ? parseInt($params.chatId) : undefined
function delChat(chatId) { function delChat (chatId) {
if (activeChatId === chatId) { if (activeChatId === chatId) {
// switch to another chat if deleting the active one // switch to another chat if deleting the active one
const newChatId = _.maxBy($chatsStorage.filter(chat => chat.id !== chatId), 'id').id const newChatId = _.maxBy($chatsStorage.filter(chat => chat.id !== chatId), 'id')?.id
if (!newChatId) return
replace(`/chat/:${newChatId}`).then(() => deleteChat(chatId)) replace(`/chat/:${newChatId}`).then(() => deleteChat(chatId))
} else { } else {
deleteChat(chatId) deleteChat(chatId)