Merge pull request #4266 from thearyadev/sidebar-pagination

feat: Sidebar infinite scroll (pagination)
This commit is contained in:
Timothy Jaeryang Baek
2024-08-04 15:33:09 +02:00
committed by GitHub
11 changed files with 138 additions and 37 deletions
+23 -8
View File
@@ -25,7 +25,9 @@
user,
socket,
showCallOverlay,
tools
tools,
pageSkip,
pageLimit
} from '$lib/stores';
import {
convertMessagesToHistory,
@@ -421,7 +423,9 @@
params: params,
files: chatFiles
});
await chats.set(await getChatList(localStorage.token));
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
}
}
};
@@ -467,7 +471,9 @@
params: params,
files: chatFiles
});
await chats.set(await getChatList(localStorage.token));
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
}
}
};
@@ -627,7 +633,9 @@
tags: [],
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);
} else {
await chatId.set('local');
@@ -703,7 +711,8 @@
})
);
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
return _responses;
};
@@ -949,7 +958,9 @@
params: params,
files: chatFiles
});
await chats.set(await getChatList(localStorage.token));
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
}
}
} else {
@@ -1216,7 +1227,9 @@
params: params,
files: chatFiles
});
await chats.set(await getChatList(localStorage.token));
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
}
}
} else {
@@ -1381,7 +1394,9 @@
if ($settings.saveChatHistory ?? true) {
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)
);
}
};
+2 -2
View File
@@ -1,6 +1,6 @@
<script lang="ts">
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 { toast } from 'svelte-sonner';
@@ -90,7 +90,7 @@
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) => {
@@ -2,7 +2,7 @@
import fileSaver from 'file-saver';
const { saveAs } = fileSaver;
import { chats, user, settings } from '$lib/stores';
import { chats, user, settings, scrollPaginationEnabled, pageSkip, pageLimit } from '$lib/stores';
import {
archiveAllChats,
@@ -12,7 +12,7 @@
getAllUserChats,
getChatList
} from '$lib/apis/chats';
import { getImportOrigin, convertOpenAIChats } from '$lib/utils';
import { getImportOrigin, convertOpenAIChats, disablePagination } from '$lib/utils';
import { onMount, getContext } from 'svelte';
import { goto } from '$app/navigation';
import { toast } from 'svelte-sonner';
@@ -61,7 +61,7 @@
await createNewChat(localStorage.token, chat);
}
}
disablePagination();
await chats.set(await getChatList(localStorage.token));
};
@@ -77,6 +77,7 @@
await archiveAllChats(localStorage.token).catch((error) => {
toast.error(error);
});
disablePagination();
await chats.set(await getChatList(localStorage.token));
};
@@ -85,6 +86,7 @@
await deleteAllChats(localStorage.token).catch((error) => {
toast.error(error);
});
disablePagination();
await chats.set(await getChatList(localStorage.token));
};
+6 -6
View File
@@ -8,7 +8,7 @@
getTagsById,
updateChatById
} from '$lib/apis/chats';
import { tags as _tags, chats, pinnedChats } from '$lib/stores';
import { tags as _tags, chats, pinnedChats, pageSkip, pageLimit, tagView } from '$lib/stores';
import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher();
@@ -46,11 +46,7 @@
tags: tags
});
console.log($_tags);
await _tags.set(await getAllChatTags(localStorage.token));
console.log($_tags);
if ($_tags.map((t) => t.name).includes(tagName)) {
if (tagName === 'pinned') {
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
@@ -62,7 +58,11 @@
dispatch('close');
}
} else {
await chats.set(await getChatList(localStorage.token));
// if the tag we deleted is no longer a valid tag, return to main chat list view
tagView.set(false);
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}
};