Fixed playlist history

This commit is contained in:
WardPearce
2024-04-11 23:52:21 +12:00
parent 4e7be101a6
commit a2fbd27b9c
2 changed files with 13 additions and 5 deletions
+2 -2
View File
@@ -186,9 +186,9 @@ export async function deleteUnsubscribe(authorId: string) {
);
}
export async function getHistory(page: number = 1): Promise<string[]> {
export async function getHistory(page: number = 1, maxResults: number = 20): Promise<string[]> {
const resp = await fetchErrorHandle(
await fetch(buildPath(`auth/history?page=${page}`), buildAuthHeaders())
await fetch(buildPath(`auth/history?page=${page}&max_results=${maxResults}`), buildAuthHeaders())
);
return await resp.json();
}
+11 -3
View File
@@ -18,13 +18,19 @@
async function loadPageHistory() {
try {
const videoIds = await getHistory(currentPage);
const videoIds = await getHistory(currentPage, 10);
let promises = [];
for (const videoId of videoIds) {
promises.push(getVideo(videoId));
promises.push(
getVideo(videoId).catch(() => {
return null;
})
);
}
const loadedHistory = await Promise.all(promises);
const loadedHistory = (await Promise.all(promises)).filter((item) => {
return item !== null;
}) as VideoPlay[];
history = [...history, ...loadedHistory];
} catch (errorMessage: any) {
error(500, errorMessage);
@@ -34,6 +40,8 @@
async function loadMore(event: InfiniteEvent) {
const pastHistoryLen = Number(history.length);
currentPage++;
await loadPageHistory();
if (pastHistoryLen === history.length) {