"vscode:/vscode.git/clone" did not exist on "441c8f408cf451f41e784171335c0e59d5972d8e"
Commit 2c4bc7a2 authored by Aryan Kothari's avatar Aryan Kothari
Browse files

refactor: uses of `chats.set(...)` support pagi sidebar

parent 62dc486c
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
user, user,
socket, socket,
showCallOverlay, showCallOverlay,
tools tools,
pageSkip,
pageLimit
} from '$lib/stores'; } from '$lib/stores';
import { import {
convertMessagesToHistory, convertMessagesToHistory,
...@@ -418,7 +420,9 @@ ...@@ -418,7 +420,9 @@
params: params, params: params,
files: chatFiles files: chatFiles
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
} }
} }
}; };
...@@ -464,7 +468,9 @@ ...@@ -464,7 +468,9 @@
params: params, params: params,
files: chatFiles files: chatFiles
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
} }
} }
}; };
...@@ -624,7 +630,9 @@ ...@@ -624,7 +630,9 @@
tags: [], tags: [],
timestamp: Date.now() timestamp: Date.now()
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
await chatId.set(chat.id); await chatId.set(chat.id);
} else { } else {
await chatId.set('local'); await chatId.set('local');
...@@ -700,7 +708,8 @@ ...@@ -700,7 +708,8 @@
}) })
); );
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
return _responses; return _responses;
}; };
...@@ -947,7 +956,9 @@ ...@@ -947,7 +956,9 @@
params: params, params: params,
files: chatFiles files: chatFiles
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
} }
} }
} else { } else {
...@@ -1220,7 +1231,9 @@ ...@@ -1220,7 +1231,9 @@
params: params, params: params,
files: chatFiles files: chatFiles
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
} }
} }
} else { } else {
...@@ -1385,7 +1398,9 @@ ...@@ -1385,7 +1398,9 @@
if ($settings.saveChatHistory ?? true) { if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, { title: _title }); chat = await updateChatById(localStorage.token, _chatId, { title: _title });
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
} }
}; };
......
<script lang="ts"> <script lang="ts">
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { chats, config, settings, user as _user, mobile } from '$lib/stores'; import { chats, config, settings, user as _user, mobile, pageSkip, pageLimit } from '$lib/stores';
import { tick, getContext, onMount } from 'svelte'; import { tick, getContext, onMount } from 'svelte';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
history: history history: history
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
}; };
const confirmEditResponseMessage = async (messageId, content) => { const confirmEditResponseMessage = async (messageId, content) => {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import fileSaver from 'file-saver'; import fileSaver from 'file-saver';
const { saveAs } = fileSaver; const { saveAs } = fileSaver;
import { chats, user, settings } from '$lib/stores'; import { chats, user, settings, scrollPaginationEnabled, pageSkip, pageLimit } from '$lib/stores';
import { import {
archiveAllChats, archiveAllChats,
...@@ -61,7 +61,12 @@ ...@@ -61,7 +61,12 @@
await createNewChat(localStorage.token, chat); await createNewChat(localStorage.token, chat);
} }
} }
// loading all chats. disable pagination on scrol.
scrollPaginationEnabled.set(false);
// subsequent queries will calculate page size to rehydrate the ui.
// since every chat is already loaded, the calculation should now load all chats.
pageSkip.set(0);
pageLimit.set(-1);
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token));
}; };
...@@ -77,6 +82,12 @@ ...@@ -77,6 +82,12 @@
await archiveAllChats(localStorage.token).catch((error) => { await archiveAllChats(localStorage.token).catch((error) => {
toast.error(error); toast.error(error);
}); });
// loading all chats. disable pagination on scrol.
scrollPaginationEnabled.set(false);
// subsequent queries will calculate page size to rehydrate the ui.
// since every chat is already loaded, the calculation should now load all chats.
pageSkip.set(0);
pageLimit.set(-1);
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token));
}; };
...@@ -85,6 +96,12 @@ ...@@ -85,6 +96,12 @@
await deleteAllChats(localStorage.token).catch((error) => { await deleteAllChats(localStorage.token).catch((error) => {
toast.error(error); toast.error(error);
}); });
// loading all chats. disable pagination on scrol.
scrollPaginationEnabled.set(false);
// subsequent queries will calculate page size to rehydrate the ui.
// since every chat is already loaded, the calculation should now load all chats.
pageSkip.set(0);
pageLimit.set(-1);
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token));
}; };
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
getTagsById, getTagsById,
updateChatById updateChatById
} from '$lib/apis/chats'; } from '$lib/apis/chats';
import { tags as _tags, chats, pinnedChats } from '$lib/stores'; import { tags as _tags, chats, pinnedChats, pageSkip, pageLimit } from '$lib/stores';
import { createEventDispatcher, onMount } from 'svelte'; import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
...@@ -47,22 +47,29 @@ ...@@ -47,22 +47,29 @@
}); });
console.log($_tags); console.log($_tags);
await _tags.set(await getAllChatTags(localStorage.token)); await _tags.set(await getAllChatTags(localStorage.token));
console.log($_tags);
console.log('this run !!!!!');
console.log($_tags); console.log($_tags);
if ($_tags.map((t) => t.name).includes(tagName)) { if ($_tags.map((t) => t.name).includes(tagName)) {
if (tagName === 'pinned') { if (tagName === 'pinned') {
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
} else { } else {
await chats.set(await getChatListByTagName(localStorage.token, tagName)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
} }
if ($chats.find((chat) => chat.id === chatId)) { if ($chats.find((chat) => chat.id === chatId)) {
dispatch('close'); dispatch('close');
} }
} else { } else {
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
} }
}; };
......
...@@ -14,7 +14,15 @@ ...@@ -14,7 +14,15 @@
getChatListByTagName, getChatListByTagName,
updateChatById updateChatById
} from '$lib/apis/chats'; } from '$lib/apis/chats';
import { chatId, chats, mobile, pinnedChats, showSidebar } from '$lib/stores'; import {
chatId,
chats,
mobile,
pageSkip,
pageLimit,
pinnedChats,
showSidebar
} from '$lib/stores';
import ChatMenu from './ChatMenu.svelte'; import ChatMenu from './ChatMenu.svelte';
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte'; import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
...@@ -40,7 +48,9 @@ ...@@ -40,7 +48,9 @@
await updateChatById(localStorage.token, id, { await updateChatById(localStorage.token, id, {
title: _title title: _title
}); });
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
} }
}; };
...@@ -53,14 +63,16 @@ ...@@ -53,14 +63,16 @@
if (res) { if (res) {
goto(`/c/${res.id}`); goto(`/c/${res.id}`);
await chats.set(await getChatList(localStorage.token)); await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
} }
}; };
const archiveChatHandler = async (id) => { const archiveChatHandler = async (id) => {
await archiveChatById(localStorage.token, id); await archiveChatById(localStorage.token, id);
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned')); await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment