fix: loading forever if user reaches end of comments

This commit is contained in:
Alex 2022-04-21 13:58:21 +12:00
parent 5bbd37ffbf
commit c613efb7cb
1 changed files with 33 additions and 31 deletions

View File

@ -77,36 +77,38 @@ export default {
},
paginate() {
this.loading = true;
const watcherIndex = this.comments.findIndex(
(comment) => comment.continuationItemRenderer
);
if (watcherIndex) this.comments.splice(watcherIndex, 1);
this.$youtube
.getContinuation(this.continuation, "next", "web")
.then((result) => {
let processed;
if (
result.data.onResponseReceivedEndpoints.find(
(endpoints) => endpoints.reloadContinuationItemsCommand
)
) {
processed = result.data.onResponseReceivedEndpoints.map(
(endpoints) =>
endpoints.reloadContinuationItemsCommand.continuationItems
);
} else {
processed = result.data.onResponseReceivedEndpoints.map(
(endpoints) =>
endpoints.appendContinuationItemsAction.continuationItems
);
}
processed = processed.flat(1);
this.comments = this.comments.concat(processed);
this.continuation = this.findContinuation(processed);
console.log("comments", this.comments);
if (this.comments) this.loading = false;
});
if (this.continuation) {
this.loading = true;
const watcherIndex = this.comments.findIndex(
(comment) => comment.continuationItemRenderer
);
if (watcherIndex) this.comments.splice(watcherIndex, 1);
this.$youtube
.getContinuation(this.continuation, "next", "web")
.then((result) => {
let processed;
if (
result.data.onResponseReceivedEndpoints.find(
(endpoints) => endpoints.reloadContinuationItemsCommand
)
) {
processed = result.data.onResponseReceivedEndpoints.map(
(endpoints) =>
endpoints.reloadContinuationItemsCommand.continuationItems
);
} else {
processed = result.data.onResponseReceivedEndpoints.map(
(endpoints) =>
endpoints.appendContinuationItemsAction.continuationItems
);
}
processed = processed.flat(1);
this.comments = this.comments.concat(processed);
this.continuation = this.findContinuation(processed);
console.log("comments", this.comments);
if (this.comments) this.loading = false;
});
}
},
findContinuation(newResponses) {
@ -115,7 +117,7 @@ export default {
);
const newContinuation =
continuationItemParent.continuationItemRenderer.continuationEndpoint
continuationItemParent?.continuationItemRenderer.continuationEndpoint
.continuationCommand.token;
return newContinuation;