Skip to content

Commit

Permalink
fix(ui): fix request button behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCatLady committed Mar 16, 2021
1 parent c51e058 commit aebedd0
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions src/components/RequestModal/TvRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,9 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
is4k,
seasons: settings.currentSettings.partialRequestsEnabled
? selectedSeasons
: data?.seasons
.filter((season) => season.seasonNumber !== 0)
.filter(
(season) =>
!getAllRequestedSeasons().includes(season.seasonNumber)
)
.map((season) => season.seasonNumber),
: getAllSeasons().filter(
(season) => !getAllRequestedSeasons().includes(season)
),
...overrideParams,
});

Expand Down Expand Up @@ -206,6 +202,12 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
}
};

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

const getAllRequestedSeasons = (): number[] => {
const requestedSeasons = (data?.mediaInfo?.requests ?? [])
.filter(
Expand Down Expand Up @@ -259,19 +261,14 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
data &&
selectedSeasons.length >= 0 &&
selectedSeasons.length <
data?.seasons
.filter((season) => season.seasonNumber !== 0)
.filter(
(season) => !getAllRequestedSeasons().includes(season.seasonNumber)
).length
getAllSeasons().filter(
(season) => !getAllRequestedSeasons().includes(season)
).length
) {
setSelectedSeasons(
data.seasons
.filter((season) => season.seasonNumber !== 0)
.filter(
(season) => !getAllRequestedSeasons().includes(season.seasonNumber)
)
.map((season) => season.seasonNumber)
getAllSeasons().filter(
(season) => !getAllRequestedSeasons().includes(season)
)
);
} else {
setSelectedSeasons([]);
Expand All @@ -284,11 +281,9 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
}
return (
selectedSeasons.length ===
data.seasons
.filter((season) => season.seasonNumber !== 0)
.filter(
(season) => !getAllRequestedSeasons().includes(season.seasonNumber)
).length
getAllSeasons().filter(
(season) => !getAllRequestedSeasons().includes(season)
).length
);
};

Expand Down Expand Up @@ -345,11 +340,10 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
okText={
editRequest && selectedSeasons.length === 0
? 'Cancel Request'
: getAllRequestedSeasons().length >= getAllSeasons().length
? intl.formatMessage(messages.alreadyrequested)
: !settings.currentSettings.partialRequestsEnabled
? getAllRequestedSeasons().length >=
(data?.mediaInfo?.seasons ?? []).length
? intl.formatMessage(messages.alreadyrequested)
: intl.formatMessage(messages.requestall)
? intl.formatMessage(messages.requestall)
: selectedSeasons.length === 0
? intl.formatMessage(messages.selectseason)
: intl.formatMessage(messages.requestseasons, {
Expand All @@ -359,8 +353,7 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
okDisabled={
editRequest
? false
: getAllRequestedSeasons().length >=
(data?.mediaInfo?.seasons ?? []).length ||
: getAllRequestedSeasons().length >= getAllSeasons().length ||
(settings.currentSettings.partialRequestsEnabled &&
selectedSeasons.length === 0)
}
Expand Down Expand Up @@ -401,8 +394,7 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
],
{ type: 'or' }
) &&
getAllRequestedSeasons().length <
(data?.mediaInfo?.seasons ?? []).length &&
getAllRequestedSeasons().length < getAllSeasons().length &&
!editRequest && (
<p className="mt-6">
<Alert
Expand Down

0 comments on commit aebedd0

Please sign in to comment.