fix(Search): Fix it occasionally returning only a small number of results (#720)

This commit is contained in:
absidue
2024-08-03 14:40:02 +02:00
committed by GitHub
parent 4f5635ad07
commit 2c0bb237e1

View File

@@ -8,13 +8,15 @@ import SearchSubMenu from '../classes/SearchSubMenu.js';
import SectionList from '../classes/SectionList.js';
import UniversalWatchCard from '../classes/UniversalWatchCard.js';
import { observe } from '../helpers.js';
import type { ApiResponse, Actions } from '../../core/index.js';
import type { ObservedArray, YTNode } from '../helpers.js';
import type { ISearchResponse } from '../types/index.js';
export default class Search extends Feed<ISearchResponse> {
header?: SearchHeader;
results?: ObservedArray<YTNode> | null;
results: ObservedArray<YTNode>;
refinements: string[];
estimated_results: number;
sub_menu?: SearchSubMenu;
@@ -34,9 +36,7 @@ export default class Search extends Feed<ISearchResponse> {
if (this.page.header)
this.header = this.page.header.item().as(SearchHeader);
this.results = contents.find(
(content) => content.is(ItemSection) && (content.contents && content.contents.length > 0)
)?.as(ItemSection)?.contents;
this.results = observe(contents.filterType(ItemSection).flatMap((section) => section.contents));
this.refinements = this.page.refinements || [];
this.estimated_results = this.page.estimated_results || 0;