Fixed playlist history
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user