diff --git a/src/lib/components/chat/Settings/ArchivedChats.svelte b/src/lib/components/chat/Settings/ArchivedChats.svelte index 32983b6206..7a1fb92b5c 100644 --- a/src/lib/components/chat/Settings/ArchivedChats.svelte +++ b/src/lib/components/chat/Settings/ArchivedChats.svelte @@ -6,7 +6,7 @@ import dayjs from 'dayjs'; import calendar from 'dayjs/plugin/calendar'; import localizedFormat from 'dayjs/plugin/localizedFormat'; - import { getContext, onMount } from 'svelte'; + import { getContext, onMount, tick } from 'svelte'; import type { Writable } from 'svelte/store'; import { goto } from '$app/navigation'; import { toast } from 'svelte-sonner'; @@ -47,6 +47,8 @@ let page = 1; let query = ''; + let searchInput: HTMLInputElement; + let chatListElement: HTMLDivElement; let orderBy = 'updated_at'; let direction = 'desc'; @@ -119,12 +121,18 @@ }; const unarchiveHandler = async (id: string) => { + const index = chatList?.findIndex((chat) => chat.id === id) ?? -1; await archiveChatById(localStorage.token, id).catch((error) => { toast.error(`${error}`); }); chatList = chatList?.filter((chat) => chat.id !== id) ?? null; if (chatCount !== null) chatCount -= 1; + + await tick(); + const rows = chatListElement?.children ?? []; + (rows[Math.min(index, rows.length - 1)]?.querySelector('button') ?? searchInput)?.focus(); + await refreshChatList(localStorage.token, { refreshPinned: true }); }; @@ -198,6 +206,7 @@
-
+
{#each chatList as chat (chat.id)}