Skip to content

Commit

Permalink
fix: series displayed an empty season with series list/request modal (#…
Browse files Browse the repository at this point in the history
…3147)

* fix: series would show an empty season on season list or tv request modal

* fix: request more would show even if all requestable seasons are already requested

* fix: will check if request or season length is longer
  • Loading branch information
OwsleyJr committed Jan 4, 2023
1 parent e084649 commit 2179637
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
9 changes: 7 additions & 2 deletions src/components/RequestModal/TvRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ const TvRequestModal = ({

const getAllSeasons = (): number[] => {
return (data?.seasons ?? [])
.filter((season) => season.seasonNumber !== 0)
.filter(
(season) => season.seasonNumber !== 0 && season.episodeCount !== 0
)
.map((season) => season.seasonNumber);
};

Expand Down Expand Up @@ -555,7 +557,10 @@ const TvRequestModal = ({
</thead>
<tbody className="divide-y divide-gray-700">
{data?.seasons
.filter((season) => season.seasonNumber !== 0)
.filter(
(season) =>
season.seasonNumber !== 0 && season.episodeCount !== 0
)
.map((season) => {
const seasonRequest = getSeasonRequest(
season.seasonNumber
Expand Down
56 changes: 36 additions & 20 deletions src/components/TvDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
FilmIcon,
PlayIcon,
} from '@heroicons/react/24/outline';
import { ChevronUpIcon } from '@heroicons/react/24/solid';
import { ChevronDownIcon } from '@heroicons/react/24/solid';
import type { RTRating } from '@server/api/rottentomatoes';
import { ANIME_KEYWORD_ID } from '@server/api/themoviedb/constants';
import { IssueStatus } from '@server/constants/issue';
Expand Down Expand Up @@ -193,7 +193,7 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
}

const seasonCount = data.seasons.filter(
(season) => season.seasonNumber !== 0
(season) => season.seasonNumber !== 0 && season.episodeCount !== 0
).length;

if (seasonCount) {
Expand Down Expand Up @@ -221,25 +221,37 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
);
}

const isComplete =
seasonCount <=
(
data.mediaInfo?.seasons.filter(
(season) =>
season.status === MediaStatus.AVAILABLE ||
season.status === MediaStatus.PARTIALLY_AVAILABLE
) ?? []
).length;
const getAllRequestedSeasons = (is4k: boolean): number[] => {
const requestedSeasons = (data?.mediaInfo?.requests ?? [])
.filter(
(request) =>
request.is4k === is4k &&
request.status !== MediaRequestStatus.DECLINED
)
.reduce((requestedSeasons, request) => {
return [
...requestedSeasons,
...request.seasons.map((sr) => sr.seasonNumber),
];
}, [] as number[]);

const is4kComplete =
seasonCount <=
(
data.mediaInfo?.seasons.filter(
const availableSeasons = (data?.mediaInfo?.seasons ?? [])
.filter(
(season) =>
season.status4k === MediaStatus.AVAILABLE ||
season.status4k === MediaStatus.PARTIALLY_AVAILABLE
) ?? []
).length;
(season[is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE ||
season[is4k ? 'status4k' : 'status'] ===
MediaStatus.PARTIALLY_AVAILABLE ||
season[is4k ? 'status4k' : 'status'] === MediaStatus.PROCESSING) &&
!requestedSeasons.includes(season.seasonNumber)
)
.map((season) => season.seasonNumber);

return [...requestedSeasons, ...availableSeasons];
};

const isComplete = seasonCount <= getAllRequestedSeasons(false).length;

const is4kComplete = seasonCount <= getAllRequestedSeasons(true).length;

const streamingProviders =
data?.watchProviders?.find((provider) => provider.iso_3166_1 === region)
Expand Down Expand Up @@ -539,6 +551,10 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
) && r.is4k
);

if (season.episodeCount === 0) {
return null;
}

return (
<Disclosure key={`season-discoslure-${season.seasonNumber}`}>
{({ open }) => (
Expand Down Expand Up @@ -709,7 +725,7 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
</div>
</>
)}
<ChevronUpIcon
<ChevronDownIcon
className={`${
open ? 'rotate-180 transform' : ''
} h-6 w-6 text-gray-500`}
Expand Down

0 comments on commit 2179637

Please sign in to comment.