diff --git a/materialious/src/lib/Api/index.ts b/materialious/src/lib/Api/index.ts index 9d5afc97..7ad07202 100644 --- a/materialious/src/lib/Api/index.ts +++ b/materialious/src/lib/Api/index.ts @@ -186,9 +186,9 @@ export async function deleteUnsubscribe(authorId: string) { ); } -export async function getHistory(page: number = 1): Promise { +export async function getHistory(page: number = 1, maxResults: number = 20): Promise { 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(); } diff --git a/materialious/src/routes/history/+page.svelte b/materialious/src/routes/history/+page.svelte index 9bc19456..9926d318 100644 --- a/materialious/src/routes/history/+page.svelte +++ b/materialious/src/routes/history/+page.svelte @@ -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) {