fix(ui): Handle missing movie/series data (#862)

pull/875/head
TheCatLady 4 years ago committed by GitHub
parent 53f6f59798
commit 7c0ddad653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -131,6 +131,18 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
revalidate(); revalidate();
}; };
const movieAttributes = [];
if (data.runtime) {
movieAttributes.push(
intl.formatMessage({ ...messages.runtime }, { minutes: data.runtime })
);
}
if (data.genres.length) {
movieAttributes.push(data.genres.map((g) => g.name).join(', '));
}
return ( return (
<div <div
className="px-4 pt-16 -mx-4 -mt-16 bg-center bg-cover" className="px-4 pt-16 -mx-4 -mt-16 bg-center bg-cover"
@ -354,19 +366,12 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
</div> </div>
<h1 className="text-2xl lg:text-4xl"> <h1 className="text-2xl lg:text-4xl">
{data.title}{' '} {data.title}{' '}
{data.releaseDate && (
<span className="text-2xl">({data.releaseDate.slice(0, 4)})</span> <span className="text-2xl">({data.releaseDate.slice(0, 4)})</span>
)}
</h1> </h1>
<span className="mt-1 text-xs lg:text-base lg:mt-0"> <span className="mt-1 text-xs lg:text-base lg:mt-0">
{(data.runtime ?? 0) > 0 && ( {movieAttributes.join(' | ')}
<>
<FormattedMessage
{...messages.runtime}
values={{ minutes: data.runtime }}
/>{' '}
|{' '}
</>
)}
{data.genres.map((g) => g.name).join(', ')}
</span> </span>
</div> </div>
<div className="relative z-10 flex flex-wrap justify-center flex-shrink-0 mt-4 sm:justify-end sm:flex-nowrap lg:mt-0"> <div className="relative z-10 flex flex-wrap justify-center flex-shrink-0 mt-4 sm:justify-end sm:flex-nowrap lg:mt-0">
@ -568,10 +573,11 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
</div> </div>
)} )}
<div className="bg-gray-900 border border-gray-800 rounded-lg shadow"> <div className="bg-gray-900 border border-gray-800 rounded-lg shadow">
{(data.voteCount > 0 || ratingData) && ( {(data.voteCount ||
(ratingData?.criticsRating && ratingData?.criticsScore) ||
(ratingData?.audienceRating && ratingData?.audienceScore)) && (
<div className="flex items-center justify-center px-4 py-2 border-b border-gray-800 last:border-b-0"> <div className="flex items-center justify-center px-4 py-2 border-b border-gray-800 last:border-b-0">
{ratingData?.criticsRating && {ratingData?.criticsRating && ratingData?.criticsScore && (
(ratingData?.criticsScore ?? 0) > 0 && (
<> <>
<span className="text-sm"> <span className="text-sm">
{ratingData.criticsRating === 'Rotten' ? ( {ratingData.criticsRating === 'Rotten' ? (
@ -585,8 +591,7 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
</span> </span>
</> </>
)} )}
{ratingData?.audienceRating && {ratingData?.audienceRating && ratingData?.audienceScore && (
(ratingData?.audienceScore ?? 0) > 0 && (
<> <>
<span className="text-sm"> <span className="text-sm">
{ratingData.audienceRating === 'Spilled' ? ( {ratingData.audienceRating === 'Spilled' ? (
@ -612,6 +617,7 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
)} )}
</div> </div>
)} )}
{data.releaseDate && (
<div className="flex px-4 py-2 border-b border-gray-800 last:border-b-0"> <div className="flex px-4 py-2 border-b border-gray-800 last:border-b-0">
<span className="text-sm"> <span className="text-sm">
<FormattedMessage {...messages.releasedate} /> <FormattedMessage {...messages.releasedate} />
@ -625,6 +631,7 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
/> />
</span> </span>
</div> </div>
)}
<div className="flex px-4 py-2 border-b border-gray-800 last:border-b-0"> <div className="flex px-4 py-2 border-b border-gray-800 last:border-b-0">
<span className="text-sm"> <span className="text-sm">
<FormattedMessage {...messages.status} /> <FormattedMessage {...messages.status} />
@ -700,6 +707,8 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
</div> </div>
</div> </div>
</div> </div>
{data.credits.cast.length > 0 && (
<>
<div className="mt-6 mb-4 md:flex md:items-center md:justify-between"> <div className="mt-6 mb-4 md:flex md:items-center md:justify-between">
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<Link href="/movie/[movieId]/cast" as={`/movie/${data.id}/cast`}> <Link href="/movie/[movieId]/cast" as={`/movie/${data.id}/cast`}>
@ -729,7 +738,7 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
sliderKey="cast" sliderKey="cast"
isLoading={false} isLoading={false}
isEmpty={false} isEmpty={false}
items={data?.credits.cast.slice(0, 20).map((person) => ( items={data.credits.cast.slice(0, 20).map((person) => (
<PersonCard <PersonCard
key={`cast-item-${person.id}`} key={`cast-item-${person.id}`}
personId={person.id} personId={person.id}
@ -739,6 +748,8 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
/> />
))} ))}
/> />
</>
)}
<MediaSlider <MediaSlider
sliderKey="recommendations" sliderKey="recommendations"
title={intl.formatMessage(messages.recommendations)} title={intl.formatMessage(messages.recommendations)}

@ -386,9 +386,9 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
</span> </span>
</div> </div>
<h1 className="text-2xl lg:text-4xl"> <h1 className="text-2xl lg:text-4xl">
<span>{data.name}</span> {data.name}{' '}
{data.firstAirDate && ( {data.firstAirDate && (
<span className="ml-2 text-2xl"> <span className="text-2xl">
({data.firstAirDate.slice(0, 4)}) ({data.firstAirDate.slice(0, 4)})
</span> </span>
)} )}
@ -591,10 +591,11 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
</div> </div>
<div className="w-full mt-8 md:w-80 md:mt-0"> <div className="w-full mt-8 md:w-80 md:mt-0">
<div className="bg-gray-900 border border-gray-800 rounded-lg shadow"> <div className="bg-gray-900 border border-gray-800 rounded-lg shadow">
{(data.voteCount > 0 || ratingData) && ( {(data.voteCount ||
(ratingData?.criticsRating && ratingData?.criticsScore) ||
(ratingData?.audienceRating && ratingData?.audienceScore)) && (
<div className="flex items-center justify-center px-4 py-2 border-b border-gray-800 last:border-b-0"> <div className="flex items-center justify-center px-4 py-2 border-b border-gray-800 last:border-b-0">
{ratingData?.criticsRating && {ratingData?.criticsRating && ratingData?.criticsScore && (
(ratingData?.criticsScore ?? 0) > 0 && (
<> <>
<span className="text-sm"> <span className="text-sm">
{ratingData.criticsRating === 'Rotten' ? ( {ratingData.criticsRating === 'Rotten' ? (
@ -608,8 +609,7 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
</span> </span>
</> </>
)} )}
{ratingData?.audienceRating && {ratingData?.audienceRating && ratingData?.audienceScore && (
(ratingData?.audienceScore ?? 0) > 0 && (
<> <>
<span className="text-sm"> <span className="text-sm">
{ratingData.audienceRating === 'Spilled' ? ( {ratingData.audienceRating === 'Spilled' ? (
@ -724,6 +724,8 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
</div> </div>
</div> </div>
</div> </div>
{data.credits.cast.length > 0 && (
<>
<div className="mt-6 mb-4 md:flex md:items-center md:justify-between"> <div className="mt-6 mb-4 md:flex md:items-center md:justify-between">
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<Link href="/tv/[tvId]/cast" as={`/tv/${data.id}/cast`}> <Link href="/tv/[tvId]/cast" as={`/tv/${data.id}/cast`}>
@ -753,7 +755,7 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
sliderKey="cast" sliderKey="cast"
isLoading={false} isLoading={false}
isEmpty={false} isEmpty={false}
items={data?.credits.cast.slice(0, 20).map((person) => ( items={data.credits.cast.slice(0, 20).map((person) => (
<PersonCard <PersonCard
key={`cast-item-${person.id}`} key={`cast-item-${person.id}`}
personId={person.id} personId={person.id}
@ -763,6 +765,8 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
/> />
))} ))}
/> />
</>
)}
<MediaSlider <MediaSlider
sliderKey="recommendations" sliderKey="recommendations"
title={intl.formatMessage(messages.recommendations)} title={intl.formatMessage(messages.recommendations)}

Loading…
Cancel
Save