From aebedd05db065bc1eef580a19d1abd36d8780966 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Mon, 15 Mar 2021 23:19:11 -0400 Subject: [PATCH] fix(ui): fix request button behavior --- .../RequestModal/TvRequestModal.tsx | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/components/RequestModal/TvRequestModal.tsx b/src/components/RequestModal/TvRequestModal.tsx index b6bccd592d..8aa0316513 100644 --- a/src/components/RequestModal/TvRequestModal.tsx +++ b/src/components/RequestModal/TvRequestModal.tsx @@ -168,13 +168,9 @@ const TvRequestModal: React.FC = ({ 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, }); @@ -206,6 +202,12 @@ const TvRequestModal: React.FC = ({ } }; + const getAllSeasons = (): number[] => { + return (data?.seasons ?? []) + .filter((season) => season.seasonNumber !== 0) + .map((season) => season.seasonNumber); + }; + const getAllRequestedSeasons = (): number[] => { const requestedSeasons = (data?.mediaInfo?.requests ?? []) .filter( @@ -259,19 +261,14 @@ const TvRequestModal: React.FC = ({ 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([]); @@ -284,11 +281,9 @@ const TvRequestModal: React.FC = ({ } return ( selectedSeasons.length === - data.seasons - .filter((season) => season.seasonNumber !== 0) - .filter( - (season) => !getAllRequestedSeasons().includes(season.seasonNumber) - ).length + getAllSeasons().filter( + (season) => !getAllRequestedSeasons().includes(season) + ).length ); }; @@ -345,11 +340,10 @@ const TvRequestModal: React.FC = ({ 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, { @@ -359,8 +353,7 @@ const TvRequestModal: React.FC = ({ okDisabled={ editRequest ? false - : getAllRequestedSeasons().length >= - (data?.mediaInfo?.seasons ?? []).length || + : getAllRequestedSeasons().length >= getAllSeasons().length || (settings.currentSettings.partialRequestsEnabled && selectedSeasons.length === 0) } @@ -401,8 +394,7 @@ const TvRequestModal: React.FC = ({ ], { type: 'or' } ) && - getAllRequestedSeasons().length < - (data?.mediaInfo?.seasons ?? []).length && + getAllRequestedSeasons().length < getAllSeasons().length && !editRequest && (