diff --git a/src/apps/stable/features/search/api/useLiveTvSearch.ts b/src/apps/stable/features/search/api/useLiveTvSearch.ts index 6fc015f96e..bb87e0b6b5 100644 --- a/src/apps/stable/features/search/api/useLiveTvSearch.ts +++ b/src/apps/stable/features/search/api/useLiveTvSearch.ts @@ -9,11 +9,11 @@ import { CardShape } from 'utils/card'; import { Section } from '../types'; import { fetchItemsByType } from './fetchItemsByType'; -const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: string | undefined, signal: AbortSignal) => { +const fetchLiveTv = (api: Api, userId: string | undefined, searchTerm: string | undefined, signal: AbortSignal) => { const sections: Section[] = []; // Movies row - const moviesData = await fetchItemsByType( + const movies = fetchItemsByType( api, userId, { @@ -22,14 +22,15 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str searchTerm: searchTerm }, { signal } - ); - addSection(sections, 'Movies', moviesData.Items, { - ...LIVETV_CARD_OPTIONS, - shape: CardShape.PortraitOverflow + ).then(moviesData => { + addSection(sections, 'Movies', moviesData.Items, { + ...LIVETV_CARD_OPTIONS, + shape: CardShape.PortraitOverflow + }); }); // Episodes row - const episodesData = await fetchItemsByType( + const episodes = fetchItemsByType( api, userId, { @@ -42,13 +43,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str searchTerm: searchTerm }, { signal } - ); - addSection(sections, 'Episodes', episodesData.Items, { - ...LIVETV_CARD_OPTIONS + ).then(episodesData => { + addSection(sections, 'Episodes', episodesData.Items, { + ...LIVETV_CARD_OPTIONS + }); }); // Sports row - const sportsData = await fetchItemsByType( + const sports = fetchItemsByType( api, userId, { @@ -57,13 +59,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str searchTerm: searchTerm }, { signal } - ); - addSection(sections, 'Sports', sportsData.Items, { - ...LIVETV_CARD_OPTIONS + ).then(sportsData => { + addSection(sections, 'Sports', sportsData.Items, { + ...LIVETV_CARD_OPTIONS + }); }); // Kids row - const kidsData = await fetchItemsByType( + const kids = fetchItemsByType( api, userId, { @@ -72,13 +75,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str searchTerm: searchTerm }, { signal } - ); - addSection(sections, 'Kids', kidsData.Items, { - ...LIVETV_CARD_OPTIONS + ).then(kidsData => { + addSection(sections, 'Kids', kidsData.Items, { + ...LIVETV_CARD_OPTIONS + }); }); // News row - const newsData = await fetchItemsByType( + const news = fetchItemsByType( api, userId, { @@ -87,13 +91,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str searchTerm: searchTerm }, { signal } - ); - addSection(sections, 'News', newsData.Items, { - ...LIVETV_CARD_OPTIONS + ).then(newsData => { + addSection(sections, 'News', newsData.Items, { + ...LIVETV_CARD_OPTIONS + }); }); // Programs row - const programsData = await fetchItemsByType( + const programs = fetchItemsByType( api, userId, { @@ -106,13 +111,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str searchTerm: searchTerm }, { signal } - ); - addSection(sections, 'Programs', programsData.Items, { - ...LIVETV_CARD_OPTIONS + ).then(programsData => { + addSection(sections, 'Programs', programsData.Items, { + ...LIVETV_CARD_OPTIONS + }); }); // Channels row - const channelsData = await fetchItemsByType( + const channels = fetchItemsByType( api, userId, { @@ -120,10 +126,11 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str searchTerm: searchTerm }, { signal } - ); - addSection(sections, 'Channels', channelsData.Items); + ).then(channelsData => { + addSection(sections, 'Channels', channelsData.Items); + }); - return sections; + return Promise.all([ movies, episodes, sports, kids, news, programs, channels ]).then(() => sections); }; export const useLiveTvSearch = ( @@ -136,7 +143,7 @@ export const useLiveTvSearch = ( return useQuery({ queryKey: ['LiveTv', collectionType, parentId, searchTerm], - queryFn: async ({ signal }) => + queryFn: ({ signal }) => fetchLiveTv(api!, userId!, searchTerm, signal), enabled: !!api && !!userId && !!collectionType && !!isLivetv(collectionType) }); diff --git a/src/apps/stable/features/search/api/useSearchItems.ts b/src/apps/stable/features/search/api/useSearchItems.ts index 0b0662b623..cb0a815373 100644 --- a/src/apps/stable/features/search/api/useSearchItems.ts +++ b/src/apps/stable/features/search/api/useSearchItems.ts @@ -33,6 +33,10 @@ export const useSearchItems = ( return useQuery({ queryKey: ['SearchItems', collectionType, parentId, searchTerm], queryFn: async ({ signal }) => { + if (liveTvSections) { + return sortSections(liveTvSections); + } + const sections: Section[] = []; addSection(sections, 'Artists', artists?.Items, { @@ -47,10 +51,6 @@ export const useSearchItems = ( showParentTitle: true }); - if (liveTvSections) { - sections.push(...liveTvSections); - } - const itemTypes: BaseItemKind[] = getItemTypesFromCollectionType(collectionType); const searchData = await fetchItemsByType( diff --git a/src/apps/stable/features/search/constants/sectionSortOrder.ts b/src/apps/stable/features/search/constants/sectionSortOrder.ts index bd5e53b81f..86ddb6733f 100644 --- a/src/apps/stable/features/search/constants/sectionSortOrder.ts +++ b/src/apps/stable/features/search/constants/sectionSortOrder.ts @@ -1,20 +1,18 @@ -import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client'; - -export const SEARCH_SECTIONS_SORT_ORDER: BaseItemKind[] = [ - BaseItemKind.Movie, - BaseItemKind.Series, - BaseItemKind.Episode, - BaseItemKind.Person, - BaseItemKind.Playlist, - BaseItemKind.MusicArtist, - BaseItemKind.MusicAlbum, - BaseItemKind.Audio, - BaseItemKind.Video, - BaseItemKind.LiveTvProgram, - BaseItemKind.TvChannel, - BaseItemKind.PhotoAlbum, - BaseItemKind.Photo, - BaseItemKind.AudioBook, - BaseItemKind.Book, - BaseItemKind.BoxSet +export const SEARCH_SECTIONS_SORT_ORDER = [ + 'Movies', + 'Shows', + 'Episodes', + 'People', + 'Playlists', + 'Artists', + 'Albums', + 'Songs', + 'HeaderVideos', + 'Programs', + 'Channels', + 'HeaderPhotoAlbums', + 'Photos', + 'HeaderAudioBooks', + 'Books', + 'Collections' ]; diff --git a/src/apps/stable/features/search/types.ts b/src/apps/stable/features/search/types.ts index 1544178bc6..db2aea2cec 100644 --- a/src/apps/stable/features/search/types.ts +++ b/src/apps/stable/features/search/types.ts @@ -1,10 +1,8 @@ -import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client'; import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client/models/base-item-dto'; import { CardOptions } from 'types/cardOptions'; export interface Section { title: string items: BaseItemDto[]; - sectionType: BaseItemKind; cardOptions?: CardOptions; }; diff --git a/src/apps/stable/features/search/utils/search.ts b/src/apps/stable/features/search/utils/search.ts index 8ff0458a8a..ec06b099d9 100644 --- a/src/apps/stable/features/search/utils/search.ts +++ b/src/apps/stable/features/search/utils/search.ts @@ -25,15 +25,15 @@ export function addSection( items: BaseItemDto[] | null | undefined, cardOptions?: CardOptions ) { - if (items && items?.length > 0 && items[0].Type) { - sections.push({ title, items, sectionType: items[0].Type, cardOptions }); + if (items && items?.length > 0) { + sections.push({ title, items, cardOptions }); } } export function sortSections(sections: Section[]) { return sections.sort((a, b) => { - const indexA = SEARCH_SECTIONS_SORT_ORDER.indexOf(a.sectionType); - const indexB = SEARCH_SECTIONS_SORT_ORDER.indexOf(b.sectionType); + const indexA = SEARCH_SECTIONS_SORT_ORDER.indexOf(a.title); + const indexB = SEARCH_SECTIONS_SORT_ORDER.indexOf(b.title); if (indexA > indexB) { return 1;