|
@@ -18,7 +18,6 @@
|
|
import { onMount, getContext, tick } from 'svelte';
|
|
import { onMount, getContext, tick } from 'svelte';
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
const i18n = getContext('i18n');
|
|
- import { disablePagination, enablePagination } from '$lib/utils';
|
|
|
|
|
|
|
|
import { updateUserSettings } from '$lib/apis/users';
|
|
import { updateUserSettings } from '$lib/apis/users';
|
|
import {
|
|
import {
|
|
@@ -56,7 +55,7 @@
|
|
let filteredChatList = [];
|
|
let filteredChatList = [];
|
|
|
|
|
|
// Pagination variables
|
|
// Pagination variables
|
|
- let chatListLoading = true;
|
|
|
|
|
|
+ let chatListLoading = false;
|
|
let allChatsLoaded = false;
|
|
let allChatsLoaded = false;
|
|
|
|
|
|
$: filteredChatList = $chats.filter((chat) => {
|
|
$: filteredChatList = $chats.filter((chat) => {
|
|
@@ -79,6 +78,16 @@
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ const enablePagination = async () => {
|
|
|
|
+ // Reset pagination variables
|
|
|
|
+ currentChatPage.set(1);
|
|
|
|
+ allChatsLoaded = false;
|
|
|
|
+ await chats.set(await getChatList(localStorage.token, $currentChatPage));
|
|
|
|
+
|
|
|
|
+ // Enable pagination
|
|
|
|
+ scrollPaginationEnabled.set(true);
|
|
|
|
+ };
|
|
|
|
+
|
|
const loadMoreChats = async () => {
|
|
const loadMoreChats = async () => {
|
|
chatListLoading = true;
|
|
chatListLoading = true;
|
|
|
|
|
|
@@ -104,10 +113,8 @@
|
|
});
|
|
});
|
|
|
|
|
|
showSidebar.set(window.innerWidth > BREAKPOINT);
|
|
showSidebar.set(window.innerWidth > BREAKPOINT);
|
|
-
|
|
|
|
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
|
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
|
|
- await chats.set(await getChatList(localStorage.token, $currentChatPage));
|
|
|
|
- chatListLoading = false;
|
|
|
|
|
|
+ await enablePagination();
|
|
|
|
|
|
let touchstart;
|
|
let touchstart;
|
|
let touchend;
|
|
let touchend;
|
|
@@ -439,7 +446,7 @@
|
|
bind:value={search}
|
|
bind:value={search}
|
|
on:focus={async () => {
|
|
on:focus={async () => {
|
|
// TODO: migrate backend for more scalable search mechanism
|
|
// TODO: migrate backend for more scalable search mechanism
|
|
- disablePagination();
|
|
|
|
|
|
+ scrollPaginationEnabled.set(false);
|
|
await chats.set(await getChatList(localStorage.token)); // when searching, load all chats
|
|
await chats.set(await getChatList(localStorage.token)); // when searching, load all chats
|
|
enrichChatsWithContent($chats);
|
|
enrichChatsWithContent($chats);
|
|
}}
|
|
}}
|
|
@@ -452,9 +459,7 @@
|
|
<button
|
|
<button
|
|
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
|
|
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
|
|
on:click={async () => {
|
|
on:click={async () => {
|
|
- enablePagination();
|
|
|
|
- allChatsLoaded = false;
|
|
|
|
- await chats.set(await getChatList(localStorage.token, $currentChatPage));
|
|
|
|
|
|
+ await enablePagination();
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
{$i18n.t('all')}
|
|
{$i18n.t('all')}
|
|
@@ -463,17 +468,17 @@
|
|
<button
|
|
<button
|
|
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
|
|
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
|
|
on:click={async () => {
|
|
on:click={async () => {
|
|
- disablePagination();
|
|
|
|
|
|
+ scrollPaginationEnabled.set(false);
|
|
let chatIds = await getChatListByTagName(localStorage.token, tag.name);
|
|
let chatIds = await getChatListByTagName(localStorage.token, tag.name);
|
|
if (chatIds.length === 0) {
|
|
if (chatIds.length === 0) {
|
|
await tags.set(await getAllChatTags(localStorage.token));
|
|
await tags.set(await getAllChatTags(localStorage.token));
|
|
|
|
|
|
// if the tag we deleted is no longer a valid tag, return to main chat list view
|
|
// if the tag we deleted is no longer a valid tag, return to main chat list view
|
|
- enablePagination();
|
|
|
|
- allChatsLoaded = false;
|
|
|
|
- chatIds = await getChatList(localStorage.token, $currentChatPage);
|
|
|
|
|
|
+ await enablePagination();
|
|
}
|
|
}
|
|
await chats.set(chatIds);
|
|
await chats.set(chatIds);
|
|
|
|
+
|
|
|
|
+ chatListLoading = false;
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
{tag.name}
|
|
{tag.name}
|