diff --git a/materialious/src/lib/components/watch/Comment.svelte b/materialious/src/lib/components/watch/Comment.svelte index 8654d065..332f3645 100644 --- a/materialious/src/lib/components/watch/Comment.svelte +++ b/materialious/src/lib/components/watch/Comment.svelte @@ -23,7 +23,7 @@ const replyText: string = comment.replies?.replyCount > 1 ? $_('replies') : $_('reply'); async function loadReplies(continuation: string) { - if (comment.getReplies) { + if (comment?.getReplies) { replies = await comment.getReplies(); } else { try { diff --git a/materialious/src/routes/(app)/search/[slug]/+page.svelte b/materialious/src/routes/(app)/search/[slug]/+page.svelte index 8f6fb22a..f6dc3de0 100644 --- a/materialious/src/routes/(app)/search/[slug]/+page.svelte +++ b/materialious/src/routes/(app)/search/[slug]/+page.svelte @@ -73,9 +73,12 @@ const searchCacheItem = $searchCacheStore[data.searchStoreId]; - if (searchCacheItem.getContinuation) { + if (searchCacheItem?.getContinuation) { newSearch = await searchCacheItem.getContinuation(); - searchCacheItem.getContinuation = newSearch.getContinuation; + + if (newSearch.getContinuation) { + searchCacheItem.getContinuation = newSearch.getContinuation; + } } else { currentPage++; searchOptions = { @@ -84,6 +87,11 @@ }; newSearch = await getSearch(data.slug, searchOptions); + + // Set the continuation method if it exists + if (newSearch.getContinuation) { + searchCacheItem.getContinuation = newSearch.getContinuation; + } } if (newSearch.length === 0) { @@ -92,7 +100,6 @@ searchCacheStore.set({ [data.searchStoreId]: [...(searchCacheItem ?? []), ...newSearch] }); - event.detail.loaded(); } } diff --git a/materialious/src/routes/(app)/watch/[slug]/+page.svelte b/materialious/src/routes/(app)/watch/[slug]/+page.svelte index 0935f112..691c6b62 100644 --- a/materialious/src/routes/(app)/watch/[slug]/+page.svelte +++ b/materialious/src/routes/(app)/watch/[slug]/+page.svelte @@ -349,16 +349,25 @@ } let loadedComments: Comments; - if (comments.getContinuation) { - loadedComments = await comments.getContinuation(); - } else { - loadedComments = await getComments(data.video.videoId, { - continuation: comments?.continuation - }); - } - comments.continuation = loadedComments.continuation; - comments.comments = [...comments.comments, ...loadedComments.comments]; + try { + if (comments.getContinuation) { + loadedComments = await comments.getContinuation(); + } else if (comments.continuation) { + loadedComments = await getComments(data.video.videoId, { + continuation: comments.continuation + }); + } else { + return; + } + + if (loadedComments.comments.length > 0) { + comments.continuation = loadedComments.continuation; + comments.comments = [...comments.comments, ...loadedComments.comments]; + } + } catch (error) { + console.error('Error loading more comments:', error); + } } function toggleTheatreMode() {