fix(frontend): hide Request More button if all current seasons are available

fixes #343
pull/395/head
sct 4 years ago
parent 3601d442db
commit 2a4dd52275

@ -116,7 +116,7 @@ class RottenTomatoes {
public async getTVRatings( public async getTVRatings(
name: string, name: string,
year: number year?: number
): Promise<RTRating | null> { ): Promise<RTRating | null> {
try { try {
const response = await this.axios.get<RTMultiSearchResponse>( const response = await this.axios.get<RTMultiSearchResponse>(
@ -126,9 +126,13 @@ class RottenTomatoes {
} }
); );
const tvshow = response.data.tvSeries.find( let tvshow: RTTvSearchResult | undefined = response.data.tvSeries[0];
(series) => series.startYear === year
); if (year) {
tvshow = response.data.tvSeries.find(
(series) => series.startYear === year
);
}
if (!tvshow) { if (!tvshow) {
return null; return null;

@ -106,7 +106,7 @@ tvRoutes.get('/:id/ratings', async (req, res, next) => {
const rtratings = await rtapi.getTVRatings( const rtratings = await rtapi.getTVRatings(
tv.name, tv.name,
Number(tv.first_air_date.slice(0, 4)) tv.first_air_date ? Number(tv.first_air_date.slice(0, 4)) : undefined
); );
if (!rtratings) { if (!rtratings) {

@ -138,6 +138,14 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
} }
}; };
const isComplete =
data.seasons.filter((season) => season.seasonNumber !== 0).length <=
(
data.mediaInfo?.seasons.filter(
(season) => season.status === MediaStatus.AVAILABLE
) ?? []
).length;
return ( return (
<div <div
className="bg-cover bg-center -mx-4 -mt-2 px-4 sm:px-8 pt-4 " className="bg-cover bg-center -mx-4 -mt-2 px-4 sm:px-8 pt-4 "
@ -267,89 +275,91 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
<FormattedMessage {...messages.request} /> <FormattedMessage {...messages.request} />
</Button> </Button>
)} )}
{data.mediaInfo && data.mediaInfo.status !== MediaStatus.UNKNOWN && ( {data.mediaInfo &&
<ButtonWithDropdown data.mediaInfo.status !== MediaStatus.UNKNOWN &&
dropdownIcon={ !isComplete && (
<svg <ButtonWithDropdown
className="w-5 h-5" dropdownIcon={
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z"
clipRule="evenodd"
/>
</svg>
}
text={
<>
<svg <svg
className="w-4 mr-1" className="w-5 h-5"
fill="currentColor" fill="currentColor"
viewBox="0 0 20 20" viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
> >
<path <path
fillRule="evenodd" fillRule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z"
clipRule="evenodd" clipRule="evenodd"
/> />
</svg> </svg>
<FormattedMessage {...messages.requestmore} /> }
</> text={
}
onClick={() => setShowRequestModal(true)}
>
{hasPermission(Permission.MANAGE_REQUESTS) &&
activeRequests &&
activeRequests.length > 0 && (
<> <>
<ButtonWithDropdown.Item <svg
onClick={() => modifyRequests('approve')} className="w-4 mr-1"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
> >
<svg <path
className="w-4 mr-1" fillRule="evenodd"
fill="currentColor" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
viewBox="0 0 20 20" clipRule="evenodd"
xmlns="http://www.w3.org/2000/svg" />
</svg>
<FormattedMessage {...messages.requestmore} />
</>
}
onClick={() => setShowRequestModal(true)}
>
{hasPermission(Permission.MANAGE_REQUESTS) &&
activeRequests &&
activeRequests.length > 0 && (
<>
<ButtonWithDropdown.Item
onClick={() => modifyRequests('approve')}
> >
<path <svg
fillRule="evenodd" className="w-4 mr-1"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" fill="currentColor"
clipRule="evenodd" viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
clipRule="evenodd"
/>
</svg>
<FormattedMessage
{...messages.approverequests}
values={{ requestCount: activeRequests.length }}
/> />
</svg> </ButtonWithDropdown.Item>
<FormattedMessage <ButtonWithDropdown.Item
{...messages.approverequests} onClick={() => modifyRequests('decline')}
values={{ requestCount: activeRequests.length }}
/>
</ButtonWithDropdown.Item>
<ButtonWithDropdown.Item
onClick={() => modifyRequests('decline')}
>
<svg
className="w-4 mr-1"
fill="currentColor"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
> >
<path <svg
fillRule="evenodd" className="w-4 mr-1"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" fill="currentColor"
clipRule="evenodd" viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clipRule="evenodd"
/>
</svg>
<FormattedMessage
{...messages.declinerequests}
values={{ requestCount: activeRequests.length }}
/> />
</svg> </ButtonWithDropdown.Item>
<FormattedMessage </>
{...messages.declinerequests} )}
values={{ requestCount: activeRequests.length }} </ButtonWithDropdown>
/> )}
</ButtonWithDropdown.Item>
</>
)}
</ButtonWithDropdown>
)}
{hasPermission(Permission.MANAGE_REQUESTS) && ( {hasPermission(Permission.MANAGE_REQUESTS) && (
<Button <Button
buttonType="default" buttonType="default"

Loading…
Cancel
Save