diff --git a/src/renderer/components/CommentSection/CommentSection.vue b/src/renderer/components/CommentSection/CommentSection.vue index c56780886c80d..aee638672cee4 100644 --- a/src/renderer/components/CommentSection/CommentSection.vue +++ b/src/renderer/components/CommentSection/CommentSection.vue @@ -363,6 +363,9 @@ const nextPageToken = shallowRef(null) // we need to react to new replies and showReplies being toggled const commentData = ref([]) +/** @type {import('youtubei.js').YT.Comments | undefined} */ +let localCommentsInstance + /** @type {import('vue').ComputedRef<'local' | 'invidious'>} */ const backendPreference = computed(() => { return store.getters.getBackendPreference @@ -538,8 +541,13 @@ async function getCommentDataLocal(more = false) { let comments if (more) { comments = await nextPageToken.value.getContinuation() + } else if (localCommentsInstance) { + comments = await localCommentsInstance.applySort(sortNewest.value ? 'NEWEST_FIRST' : 'TOP_COMMENTS') + localCommentsInstance = comments } else { - comments = await getLocalComments(props.id, sortNewest.value) + comments = await getLocalComments(props.id) + sortNewest.value = comments.header?.sort_menu?.sub_menu_items?.[1].selected ?? false + localCommentsInstance = comments } const parsedComments = comments.contents @@ -575,6 +583,7 @@ async function getCommentDataLocal(more = false) { nextPageToken.value = null isLoading.value = false showComments.value = true + localCommentsInstance = undefined return } // endregion No comment detection @@ -585,6 +594,7 @@ async function getCommentDataLocal(more = false) { copyToClipboard(err) }) if (backendFallback.value && backendPreference.value === 'local') { + localCommentsInstance = undefined showToast(t('Falling back to Invidious API')) getCommentDataInvidious() } else { diff --git a/src/renderer/helpers/api/local.js b/src/renderer/helpers/api/local.js index eca38551dd6af..3c75d60d874c7 100644 --- a/src/renderer/helpers/api/local.js +++ b/src/renderer/helpers/api/local.js @@ -291,11 +291,10 @@ export async function getLocalVideoInfo(id) { /** * @param {string} id - * @param {boolean | undefined} sortByNewest */ -export async function getLocalComments(id, sortByNewest = false) { +export async function getLocalComments(id) { const innertube = await createInnertube() - return innertube.getComments(id, sortByNewest ? 'NEWEST_FIRST' : 'TOP_COMMENTS') + return innertube.getComments(id) } // I know `type & type` is typescript syntax and not valid jsdoc but I couldn't get @extends or @augments to work