1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Make LiveTV synchronous

This commit is contained in:
viown 2025-03-06 10:44:03 +03:00
parent cd19e9e5e1
commit 1fd314213a
5 changed files with 63 additions and 60 deletions

View file

@ -9,11 +9,11 @@ import { CardShape } from 'utils/card';
import { Section } from '../types'; import { Section } from '../types';
import { fetchItemsByType } from './fetchItemsByType'; 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[] = []; const sections: Section[] = [];
// Movies row // Movies row
const moviesData = await fetchItemsByType( const movies = fetchItemsByType(
api, api,
userId, userId,
{ {
@ -22,14 +22,15 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str
searchTerm: searchTerm searchTerm: searchTerm
}, },
{ signal } { signal }
); ).then(moviesData => {
addSection(sections, 'Movies', moviesData.Items, { addSection(sections, 'Movies', moviesData.Items, {
...LIVETV_CARD_OPTIONS, ...LIVETV_CARD_OPTIONS,
shape: CardShape.PortraitOverflow shape: CardShape.PortraitOverflow
});
}); });
// Episodes row // Episodes row
const episodesData = await fetchItemsByType( const episodes = fetchItemsByType(
api, api,
userId, userId,
{ {
@ -42,13 +43,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str
searchTerm: searchTerm searchTerm: searchTerm
}, },
{ signal } { signal }
); ).then(episodesData => {
addSection(sections, 'Episodes', episodesData.Items, { addSection(sections, 'Episodes', episodesData.Items, {
...LIVETV_CARD_OPTIONS ...LIVETV_CARD_OPTIONS
});
}); });
// Sports row // Sports row
const sportsData = await fetchItemsByType( const sports = fetchItemsByType(
api, api,
userId, userId,
{ {
@ -57,13 +59,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str
searchTerm: searchTerm searchTerm: searchTerm
}, },
{ signal } { signal }
); ).then(sportsData => {
addSection(sections, 'Sports', sportsData.Items, { addSection(sections, 'Sports', sportsData.Items, {
...LIVETV_CARD_OPTIONS ...LIVETV_CARD_OPTIONS
});
}); });
// Kids row // Kids row
const kidsData = await fetchItemsByType( const kids = fetchItemsByType(
api, api,
userId, userId,
{ {
@ -72,13 +75,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str
searchTerm: searchTerm searchTerm: searchTerm
}, },
{ signal } { signal }
); ).then(kidsData => {
addSection(sections, 'Kids', kidsData.Items, { addSection(sections, 'Kids', kidsData.Items, {
...LIVETV_CARD_OPTIONS ...LIVETV_CARD_OPTIONS
});
}); });
// News row // News row
const newsData = await fetchItemsByType( const news = fetchItemsByType(
api, api,
userId, userId,
{ {
@ -87,13 +91,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str
searchTerm: searchTerm searchTerm: searchTerm
}, },
{ signal } { signal }
); ).then(newsData => {
addSection(sections, 'News', newsData.Items, { addSection(sections, 'News', newsData.Items, {
...LIVETV_CARD_OPTIONS ...LIVETV_CARD_OPTIONS
});
}); });
// Programs row // Programs row
const programsData = await fetchItemsByType( const programs = fetchItemsByType(
api, api,
userId, userId,
{ {
@ -106,13 +111,14 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str
searchTerm: searchTerm searchTerm: searchTerm
}, },
{ signal } { signal }
); ).then(programsData => {
addSection(sections, 'Programs', programsData.Items, { addSection(sections, 'Programs', programsData.Items, {
...LIVETV_CARD_OPTIONS ...LIVETV_CARD_OPTIONS
});
}); });
// Channels row // Channels row
const channelsData = await fetchItemsByType( const channels = fetchItemsByType(
api, api,
userId, userId,
{ {
@ -120,10 +126,11 @@ const fetchLiveTv = async (api: Api, userId: string | undefined, searchTerm: str
searchTerm: searchTerm searchTerm: searchTerm
}, },
{ signal } { signal }
); ).then(channelsData => {
addSection(sections, 'Channels', channelsData.Items); addSection(sections, 'Channels', channelsData.Items);
});
return sections; return Promise.all([ movies, episodes, sports, kids, news, programs, channels ]).then(() => sections);
}; };
export const useLiveTvSearch = ( export const useLiveTvSearch = (
@ -136,7 +143,7 @@ export const useLiveTvSearch = (
return useQuery({ return useQuery({
queryKey: ['LiveTv', collectionType, parentId, searchTerm], queryKey: ['LiveTv', collectionType, parentId, searchTerm],
queryFn: async ({ signal }) => queryFn: ({ signal }) =>
fetchLiveTv(api!, userId!, searchTerm, signal), fetchLiveTv(api!, userId!, searchTerm, signal),
enabled: !!api && !!userId && !!collectionType && !!isLivetv(collectionType) enabled: !!api && !!userId && !!collectionType && !!isLivetv(collectionType)
}); });

View file

@ -33,6 +33,10 @@ export const useSearchItems = (
return useQuery({ return useQuery({
queryKey: ['SearchItems', collectionType, parentId, searchTerm], queryKey: ['SearchItems', collectionType, parentId, searchTerm],
queryFn: async ({ signal }) => { queryFn: async ({ signal }) => {
if (liveTvSections) {
return sortSections(liveTvSections);
}
const sections: Section[] = []; const sections: Section[] = [];
addSection(sections, 'Artists', artists?.Items, { addSection(sections, 'Artists', artists?.Items, {
@ -47,10 +51,6 @@ export const useSearchItems = (
showParentTitle: true showParentTitle: true
}); });
if (liveTvSections) {
sections.push(...liveTvSections);
}
const itemTypes: BaseItemKind[] = getItemTypesFromCollectionType(collectionType); const itemTypes: BaseItemKind[] = getItemTypesFromCollectionType(collectionType);
const searchData = await fetchItemsByType( const searchData = await fetchItemsByType(

View file

@ -1,20 +1,18 @@
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client'; export const SEARCH_SECTIONS_SORT_ORDER = [
'Movies',
export const SEARCH_SECTIONS_SORT_ORDER: BaseItemKind[] = [ 'Shows',
BaseItemKind.Movie, 'Episodes',
BaseItemKind.Series, 'People',
BaseItemKind.Episode, 'Playlists',
BaseItemKind.Person, 'Artists',
BaseItemKind.Playlist, 'Albums',
BaseItemKind.MusicArtist, 'Songs',
BaseItemKind.MusicAlbum, 'HeaderVideos',
BaseItemKind.Audio, 'Programs',
BaseItemKind.Video, 'Channels',
BaseItemKind.LiveTvProgram, 'HeaderPhotoAlbums',
BaseItemKind.TvChannel, 'Photos',
BaseItemKind.PhotoAlbum, 'HeaderAudioBooks',
BaseItemKind.Photo, 'Books',
BaseItemKind.AudioBook, 'Collections'
BaseItemKind.Book,
BaseItemKind.BoxSet
]; ];

View file

@ -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 type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client/models/base-item-dto';
import { CardOptions } from 'types/cardOptions'; import { CardOptions } from 'types/cardOptions';
export interface Section { export interface Section {
title: string title: string
items: BaseItemDto[]; items: BaseItemDto[];
sectionType: BaseItemKind;
cardOptions?: CardOptions; cardOptions?: CardOptions;
}; };

View file

@ -25,15 +25,15 @@ export function addSection(
items: BaseItemDto[] | null | undefined, items: BaseItemDto[] | null | undefined,
cardOptions?: CardOptions cardOptions?: CardOptions
) { ) {
if (items && items?.length > 0 && items[0].Type) { if (items && items?.length > 0) {
sections.push({ title, items, sectionType: items[0].Type, cardOptions }); sections.push({ title, items, cardOptions });
} }
} }
export function sortSections(sections: Section[]) { export function sortSections(sections: Section[]) {
return sections.sort((a, b) => { return sections.sort((a, b) => {
const indexA = SEARCH_SECTIONS_SORT_ORDER.indexOf(a.sectionType); const indexA = SEARCH_SECTIONS_SORT_ORDER.indexOf(a.title);
const indexB = SEARCH_SECTIONS_SORT_ORDER.indexOf(b.sectionType); const indexB = SEARCH_SECTIONS_SORT_ORDER.indexOf(b.title);
if (indexA > indexB) { if (indexA > indexB) {
return 1; return 1;