2024-02-28 22:47:36 +03:00
|
|
|
import React, { type FC } from 'react';
|
2025-02-24 13:19:01 -05:00
|
|
|
import { useApi } from 'hooks/useApi';
|
2024-01-12 21:08:06 +03:00
|
|
|
import { useGetProgramsSectionsWithItems, useGetTimers } from 'hooks/useFetchItems';
|
|
|
|
import { appRouter } from 'components/router/appRouter';
|
2024-08-14 13:31:34 -04:00
|
|
|
import globalize from 'lib/globalize';
|
2024-01-12 21:08:06 +03:00
|
|
|
import Loading from 'components/loading/LoadingComponent';
|
2024-09-23 02:53:44 +03:00
|
|
|
import NoItemsMessage from 'components/common/NoItemsMessage';
|
|
|
|
import SectionContainer from 'components/common/SectionContainer';
|
2024-02-28 22:47:36 +03:00
|
|
|
import { CardShape } from 'utils/card';
|
|
|
|
import type { ParentId } from 'types/library';
|
|
|
|
import type { Section, SectionType } from 'types/sections';
|
2024-01-12 21:08:06 +03:00
|
|
|
|
|
|
|
interface ProgramsSectionViewProps {
|
|
|
|
parentId: ParentId;
|
|
|
|
sectionType: SectionType[];
|
|
|
|
isUpcomingRecordingsEnabled: boolean | undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
const ProgramsSectionView: FC<ProgramsSectionViewProps> = ({
|
|
|
|
parentId,
|
|
|
|
sectionType,
|
|
|
|
isUpcomingRecordingsEnabled = false
|
|
|
|
}) => {
|
2025-02-24 13:19:01 -05:00
|
|
|
const { __legacyApiClient__ } = useApi();
|
2024-01-31 04:32:54 +03:00
|
|
|
const { isLoading, data: sectionsWithItems, refetch } = useGetProgramsSectionsWithItems(parentId, sectionType);
|
2024-01-12 21:08:06 +03:00
|
|
|
const {
|
|
|
|
isLoading: isUpcomingRecordingsLoading,
|
|
|
|
data: upcomingRecordings
|
|
|
|
} = useGetTimers(isUpcomingRecordingsEnabled);
|
|
|
|
|
|
|
|
if (isLoading || isUpcomingRecordingsLoading) {
|
|
|
|
return <Loading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sectionsWithItems?.length && !upcomingRecordings?.length) {
|
2024-09-23 02:53:44 +03:00
|
|
|
return <NoItemsMessage />;
|
2024-01-12 21:08:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const getRouteUrl = (section: Section) => {
|
|
|
|
return appRouter.getRouteUrl('list', {
|
|
|
|
serverId: window.ApiClient.serverId(),
|
|
|
|
itemTypes: section.itemTypes,
|
|
|
|
isAiring: section.parametersOptions?.isAiring,
|
|
|
|
isMovie: section.parametersOptions?.isMovie,
|
|
|
|
isSports: section.parametersOptions?.isSports,
|
|
|
|
isKids: section.parametersOptions?.isKids,
|
|
|
|
isNews: section.parametersOptions?.isNews,
|
|
|
|
isSeries: section.parametersOptions?.isSeries
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{sectionsWithItems?.map(({ section, items }) => (
|
|
|
|
<SectionContainer
|
|
|
|
key={section.type}
|
2024-09-23 02:53:44 +03:00
|
|
|
sectionHeaderProps={{
|
|
|
|
title: globalize.translate(section.name),
|
|
|
|
url: getRouteUrl(section)
|
|
|
|
}}
|
|
|
|
itemsContainerProps={{
|
|
|
|
queryKey: ['ProgramSectionWithItems'],
|
|
|
|
reloadItems: refetch
|
|
|
|
}}
|
|
|
|
items={items}
|
2024-01-12 21:08:06 +03:00
|
|
|
cardOptions={{
|
2024-01-31 04:32:54 +03:00
|
|
|
...section.cardOptions,
|
2025-02-24 13:19:01 -05:00
|
|
|
queryKey: ['ProgramSectionWithItems'],
|
|
|
|
serverId: __legacyApiClient__?.serverId()
|
2024-01-12 21:08:06 +03:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
|
|
|
|
{upcomingRecordings?.map((group) => (
|
|
|
|
<SectionContainer
|
|
|
|
key={group.name}
|
2024-09-23 02:53:44 +03:00
|
|
|
sectionHeaderProps={{
|
|
|
|
title: group.name
|
|
|
|
}}
|
|
|
|
itemsContainerProps={{
|
|
|
|
queryKey: ['Timers'],
|
|
|
|
reloadItems: refetch
|
|
|
|
}}
|
2024-09-23 22:30:20 +03:00
|
|
|
items={group.timerInfo}
|
2024-01-12 21:08:06 +03:00
|
|
|
cardOptions={{
|
2024-01-31 04:32:54 +03:00
|
|
|
queryKey: ['Timers'],
|
2024-02-28 22:47:36 +03:00
|
|
|
shape: CardShape.BackdropOverflow,
|
2024-01-12 21:08:06 +03:00
|
|
|
showTitle: true,
|
|
|
|
showParentTitleOrTitle: true,
|
|
|
|
showAirTime: true,
|
|
|
|
showAirEndTime: true,
|
|
|
|
showChannelName: false,
|
|
|
|
cardLayout: true,
|
|
|
|
centerText: false,
|
|
|
|
action: 'edit',
|
|
|
|
cardFooterAside: 'none',
|
|
|
|
preferThumb: true,
|
|
|
|
coverImage: true,
|
|
|
|
allowBottomPadding: false,
|
|
|
|
overlayText: false,
|
2025-02-24 13:19:01 -05:00
|
|
|
showChannelLogo: true,
|
|
|
|
serverId: __legacyApiClient__?.serverId()
|
2024-01-12 21:08:06 +03:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProgramsSectionView;
|