Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Section Container #6100

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions src/apps/experimental/components/library/GenresItemsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/bas
import type { CollectionType } from '@jellyfin/sdk/lib/generated-client/models/collection-type';
import React, { FC } from 'react';
import { useGetGenres } from 'hooks/useFetchItems';
import globalize from 'lib/globalize';
import NoItemsMessage from 'components/common/NoItemsMessage';
import Loading from 'components/loading/LoadingComponent';
import GenresSectionContainer from './GenresSectionContainer';
import type { ParentId } from 'types/library';
Expand All @@ -25,27 +25,18 @@ const GenresItemsContainer: FC<GenresItemsContainerProps> = ({
}

if (!genresResult?.Items?.length) {
return (
<div className='noItemsMessage centerMessage'>
<h1>{globalize.translate('MessageNothingHere')}</h1>
<p>{globalize.translate('MessageNoGenresAvailable')}</p>
</div>
);
return <NoItemsMessage message='MessageNoGenresAvailable' />;
}

return (
<>
{genresResult.Items.map((genre) => (
<GenresSectionContainer
key={genre.Id}
collectionType={collectionType}
parentId={parentId}
itemType={itemType}
genre={genre}
/>
))}
</>
);
return genresResult.Items.map((genre) => (
<GenresSectionContainer
key={genre.Id}
collectionType={collectionType}
parentId={parentId}
itemType={itemType}
genre={genre}
/>
));
};

export default GenresItemsContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { type FC } from 'react';
import { useGetItems } from 'hooks/useFetchItems';
import Loading from 'components/loading/LoadingComponent';
import { appRouter } from 'components/router/appRouter';
import SectionContainer from './SectionContainer';
import SectionContainer from 'components/common/SectionContainer';
import { CardShape } from 'utils/card';
import type { ParentId } from 'types/library';
import type { ItemDto } from 'types/base/models/item-dto';
Expand Down Expand Up @@ -59,9 +59,12 @@ const GenresSectionContainer: FC<GenresSectionContainerProps> = ({
}

return <SectionContainer
sectionTitle={genre.Name || ''}
items={itemsResult?.Items || []}
url={getRouteUrl(genre)}
key={genre.Name}
sectionHeaderProps={{
title: genre.Name || '',
url: getRouteUrl(genre)
}}
items={itemsResult?.Items}
cardOptions={{
scalable: true,
overlayPlayButton: true,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/experimental/components/library/ItemsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const ItemsView: FC<ItemsViewProps> = ({

const getItems = useCallback(() => {
if (!itemsResult?.Items?.length) {
return <NoItemsMessage noItemsMessage={noItemsMessage} />;
return <NoItemsMessage message={noItemsMessage} />;
}

if (libraryViewSettings.ViewMode === ViewMode.ListView) {
Expand Down
36 changes: 20 additions & 16 deletions src/apps/experimental/components/library/ProgramsSectionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useGetProgramsSectionsWithItems, useGetTimers } from 'hooks/useFetchIte
import { appRouter } from 'components/router/appRouter';
import globalize from 'lib/globalize';
import Loading from 'components/loading/LoadingComponent';
import SectionContainer from './SectionContainer';
import NoItemsMessage from 'components/common/NoItemsMessage';
import SectionContainer from 'components/common/SectionContainer';
import { CardShape } from 'utils/card';
import type { ParentId } from 'types/library';
import type { Section, SectionType } from 'types/sections';
Expand All @@ -30,14 +31,7 @@ const ProgramsSectionView: FC<ProgramsSectionViewProps> = ({
}

if (!sectionsWithItems?.length && !upcomingRecordings?.length) {
return (
<div className='noItemsMessage centerMessage'>
<h1>{globalize.translate('MessageNothingHere')}</h1>
<p>
{globalize.translate('MessageNoItemsAvailable')}
</p>
</div>
);
return <NoItemsMessage />;
}

const getRouteUrl = (section: Section) => {
Expand All @@ -58,23 +52,33 @@ const ProgramsSectionView: FC<ProgramsSectionViewProps> = ({
{sectionsWithItems?.map(({ section, items }) => (
<SectionContainer
key={section.type}
sectionTitle={globalize.translate(section.name)}
items={items ?? []}
url={getRouteUrl(section)}
reloadItems={refetch}
sectionHeaderProps={{
title: globalize.translate(section.name),
url: getRouteUrl(section)
}}
itemsContainerProps={{
queryKey: ['ProgramSectionWithItems'],
reloadItems: refetch
}}
items={items}
cardOptions={{
...section.cardOptions,
queryKey: ['ProgramSectionWithItems']
}}
/>

))}

{upcomingRecordings?.map((group) => (
<SectionContainer
key={group.name}
sectionTitle={group.name}
items={group.timerInfo ?? []}
sectionHeaderProps={{
title: group.name
}}
itemsContainerProps={{
queryKey: ['Timers'],
reloadItems: refetch
}}
items={group.timerInfo}
cardOptions={{
queryKey: ['Timers'],
shape: CardShape.BackdropOverflow,
Expand Down
65 changes: 0 additions & 65 deletions src/apps/experimental/components/library/SectionContainer.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import { appRouter } from 'components/router/appRouter';
import globalize from 'lib/globalize';
import Loading from 'components/loading/LoadingComponent';
import SectionContainer from './SectionContainer';
import NoItemsMessage from 'components/common/NoItemsMessage';
import SectionContainer from '../../../../components/common/SectionContainer';
import { CardShape } from 'utils/card';
import type { ParentId } from 'types/library';
import type { Section, SectionType } from 'types/sections';
Expand Down Expand Up @@ -38,12 +39,7 @@ const SuggestionsSectionView: FC<SuggestionsSectionViewProps> = ({
}

if (!sectionsWithItems?.length && !movieRecommendationsItems?.length) {
return (
<div className='noItemsMessage centerMessage'>
<h1>{globalize.translate('MessageNothingHere')}</h1>
<p>{globalize.translate('MessageNoItemsAvailable')}</p>
</div>
);
return <NoItemsMessage />;
}

const getRouteUrl = (section: Section) => {
Expand Down Expand Up @@ -96,9 +92,14 @@ const SuggestionsSectionView: FC<SuggestionsSectionViewProps> = ({
{sectionsWithItems?.map(({ section, items }) => (
<SectionContainer
key={section.type}
sectionTitle={globalize.translate(section.name)}
items={items ?? []}
url={getRouteUrl(section)}
sectionHeaderProps={{
title: globalize.translate(section.name),
url: getRouteUrl(section)
}}
itemsContainerProps={{
queryKey: ['SuggestionSectionWithItems']
}}
items={items}
cardOptions={{
...section.cardOptions,
queryKey: ['SuggestionSectionWithItems'],
Expand All @@ -114,8 +115,13 @@ const SuggestionsSectionView: FC<SuggestionsSectionViewProps> = ({
<SectionContainer
// eslint-disable-next-line react/no-array-index-key
key={`${recommendation.CategoryId}-${index}`} // use a unique id return value may have duplicate id
sectionTitle={getRecommendationTittle(recommendation)}
items={(recommendation.Items as ItemDto[]) ?? []}
sectionHeaderProps={{
title: getRecommendationTittle(recommendation)
}}
itemsContainerProps={{
queryKey: ['MovieRecommendations']
}}
items={recommendation.Items as ItemDto[]}
cardOptions={{
queryKey: ['MovieRecommendations'],
shape: CardShape.PortraitOverflow,
Expand Down
67 changes: 31 additions & 36 deletions src/apps/experimental/components/library/UpcomingView.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
import React, { type FC } from 'react';
import Box from '@mui/material/Box';
import { useGetGroupsUpcomingEpisodes } from 'hooks/useFetchItems';
import Loading from 'components/loading/LoadingComponent';
import globalize from 'lib/globalize';
import SectionContainer from './SectionContainer';
import NoItemsMessage from 'components/common/NoItemsMessage';
import SectionContainer from 'components/common/SectionContainer';
import { CardShape } from 'utils/card';
import type { LibraryViewProps } from 'types/library';

const UpcomingView: FC<LibraryViewProps> = ({ parentId }) => {
const { isLoading, data: groupsUpcomingEpisodes } = useGetGroupsUpcomingEpisodes(parentId);
const { isLoading, data: groupsUpcomingEpisodes } =
useGetGroupsUpcomingEpisodes(parentId);

if (isLoading) return <Loading />;

return (
<Box>
{!groupsUpcomingEpisodes?.length ? (
<div className='noItemsMessage centerMessage'>
<h1>{globalize.translate('MessageNothingHere')}</h1>
<p>
{globalize.translate(
'MessagePleaseEnsureInternetMetadata'
)}
</p>
</div>
) : (
groupsUpcomingEpisodes?.map((group) => (
<SectionContainer
key={group.name}
sectionTitle={group.name}
items={group.items ?? []}
cardOptions={{
shape: CardShape.BackdropOverflow,
showLocationTypeIndicator: false,
showParentTitle: true,
preferThumb: true,
lazy: true,
showDetailsMenu: true,
missingIndicator: false,
cardLayout: false
}}
/>
))
)}
</Box>
);
if (!groupsUpcomingEpisodes?.length) {
return <NoItemsMessage message='MessagePleaseEnsureInternetMetadata' />;
}

return groupsUpcomingEpisodes?.map((group) => (
<SectionContainer
key={group.name}
sectionHeaderProps={{
title: group.name
}}
itemsContainerProps={{
queryKey: ['GroupsUpcomingEpisodes']
}}
items={group.items}
cardOptions={{
shape: CardShape.BackdropOverflow,
showLocationTypeIndicator: false,
showParentTitle: true,
preferThumb: true,
lazy: true,
showDetailsMenu: true,
missingIndicator: false,
cardLayout: false,
queryKey: ['GroupsUpcomingEpisodes']
}}
/>
));
};

export default UpcomingView;
10 changes: 5 additions & 5 deletions src/components/common/NoItemsMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import Typography from '@mui/material/Typography';
import globalize from 'lib/globalize';

interface NoItemsMessageProps {
noItemsMessage?: string;
message?: string;
}

const NoItemsMessage: FC<NoItemsMessageProps> = ({
noItemsMessage = 'MessageNoItemsAvailable'
message = 'MessageNoItemsAvailable'
}) => {
return (
<Box className='noItemsMessage centerMessage'>
<Typography variant='h2'>
<Typography variant='h1'>
{globalize.translate('MessageNothingHere')}
</Typography>
<Typography paragraph variant='h2'>
{globalize.translate(noItemsMessage)}
<Typography paragraph>
{globalize.translate(message)}
</Typography>
</Box>
);
Expand Down
Loading
Loading