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:
parent
cd19e9e5e1
commit
1fd314213a
5 changed files with 63 additions and 60 deletions
|
@ -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)
|
||||
});
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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'
|
||||
];
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue