From cdd330a01f58c92dbd45a77bb06b3014673c8379 Mon Sep 17 00:00:00 2001 From: viown <48097677+viown@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:18:39 +0300 Subject: [PATCH] Separate LiveTvProgram to a standalone query --- .../features/search/api/useProgramsSearch.ts | 50 +++++++++++++++++++ .../features/search/api/useSearchItems.ts | 10 +++- .../stable/features/search/utils/search.ts | 1 - 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/apps/stable/features/search/api/useProgramsSearch.ts diff --git a/src/apps/stable/features/search/api/useProgramsSearch.ts b/src/apps/stable/features/search/api/useProgramsSearch.ts new file mode 100644 index 0000000000..560c2e4682 --- /dev/null +++ b/src/apps/stable/features/search/api/useProgramsSearch.ts @@ -0,0 +1,50 @@ +import { Api } from '@jellyfin/sdk'; +import { CollectionType } from '@jellyfin/sdk/lib/generated-client/models/collection-type'; +import { useQuery } from '@tanstack/react-query'; +import { AxiosRequestConfig } from 'axios'; +import { useApi } from 'hooks/useApi'; +import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind'; +import { ItemsApiGetItemsRequest } from '@jellyfin/sdk/lib/generated-client/api/items-api'; +import { fetchItemsByType } from './fetchItemsByType'; + +const fetchPrograms = async ( + api: Api, + userId: string, + params?: ItemsApiGetItemsRequest, + options?: AxiosRequestConfig +) => { + const response = await fetchItemsByType( + api, + userId, + { + includeItemTypes: [BaseItemKind.LiveTvProgram], + ...params + }, + options + ); + + return response; +}; + +export const useProgramsSearch = ( + parentId?: string, + collectionType?: CollectionType, + searchTerm?: string +) => { + const { api, user } = useApi(); + const userId = user?.Id; + + return useQuery({ + queryKey: ['Search', 'Programs', collectionType, parentId, searchTerm], + queryFn: ({ signal }) => fetchPrograms( + api!, + userId!, + { + parentId: parentId, + searchTerm: searchTerm + }, + { signal } + ), + enabled: !!api && !!userId && !collectionType + }); +}; diff --git a/src/apps/stable/features/search/api/useSearchItems.ts b/src/apps/stable/features/search/api/useSearchItems.ts index a799b4fa68..0f7b44ad18 100644 --- a/src/apps/stable/features/search/api/useSearchItems.ts +++ b/src/apps/stable/features/search/api/useSearchItems.ts @@ -10,6 +10,8 @@ import { useVideoSearch } from './useVideoSearch'; import { Section } from '../types'; import { useLiveTvSearch } from './useLiveTvSearch'; import { fetchItemsByType } from './fetchItemsByType'; +import { useProgramsSearch } from './useProgramsSearch'; +import { LIVETV_CARD_OPTIONS } from '../constants/liveTvCardOptions'; export const useSearchItems = ( parentId?: string, @@ -19,6 +21,7 @@ export const useSearchItems = ( const { data: artists, isPending: isArtistsPending } = useArtistsSearch(parentId, collectionType, searchTerm); const { data: people, isPending: isPeoplePending } = usePeopleSearch(parentId, collectionType, searchTerm); const { data: videos, isPending: isVideosPending } = useVideoSearch(parentId, collectionType, searchTerm); + const { data: programs, isPending: isProgramsPending } = useProgramsSearch(parentId, collectionType, searchTerm); const { data: liveTvSections, isPending: isLiveTvPending } = useLiveTvSearch(parentId, collectionType, searchTerm); const { api, user } = useApi(); const userId = user?.Id; @@ -26,6 +29,7 @@ export const useSearchItems = ( const isArtistsEnabled = !isArtistsPending || (collectionType && !isMusic(collectionType)); const isPeopleEnabled = !isPeoplePending || (collectionType && !isMovies(collectionType) && !isTVShows(collectionType)); const isVideosEnabled = !isVideosPending || collectionType; + const isProgramsEnabled = !isProgramsPending || collectionType; const isLiveTvEnabled = !isLiveTvPending || !collectionType || !isLivetv(collectionType); return useQuery({ @@ -41,6 +45,10 @@ export const useSearchItems = ( coverImage: true }); + addSection(sections, 'Programs', programs?.Items, { + ...LIVETV_CARD_OPTIONS + }); + addSection(sections, 'People', people?.Items, { coverImage: true }); @@ -77,6 +85,6 @@ export const useSearchItems = ( return sortSections(sections); }, - enabled: !!api && !!userId && !!isArtistsEnabled && !!isPeopleEnabled && !!isVideosEnabled && !!isLiveTvEnabled + enabled: !!api && !!userId && !!isArtistsEnabled && !!isPeopleEnabled && !!isVideosEnabled && !!isLiveTvEnabled && !!isProgramsEnabled }); }; diff --git a/src/apps/stable/features/search/utils/search.ts b/src/apps/stable/features/search/utils/search.ts index 6de5138cd7..441b0a531d 100644 --- a/src/apps/stable/features/search/utils/search.ts +++ b/src/apps/stable/features/search/utils/search.ts @@ -130,7 +130,6 @@ export function getItemTypesFromCollectionType(collectionType: CollectionType | BaseItemKind.Playlist, BaseItemKind.MusicAlbum, BaseItemKind.Audio, - BaseItemKind.LiveTvProgram, BaseItemKind.TvChannel, BaseItemKind.PhotoAlbum, BaseItemKind.Photo,