-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): add full cast page for movies and series
- Loading branch information
Showing
8 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Link from 'next/link'; | ||
import { useRouter } from 'next/router'; | ||
import React, { useContext } from 'react'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
import useSWR from 'swr'; | ||
import { MovieDetails } from '../../../../server/models/Movie'; | ||
import { LanguageContext } from '../../../context/LanguageContext'; | ||
import Error from '../../../pages/_error'; | ||
import Header from '../../Common/Header'; | ||
import LoadingSpinner from '../../Common/LoadingSpinner'; | ||
import PersonCard from '../../PersonCard'; | ||
|
||
const messages = defineMessages({ | ||
fullcast: 'Full Cast', | ||
}); | ||
|
||
const MovieCast: React.FC = () => { | ||
const router = useRouter(); | ||
const intl = useIntl(); | ||
const { locale } = useContext(LanguageContext); | ||
const { data, error } = useSWR<MovieDetails>( | ||
`/api/v1/movie/${router.query.movieId}?language=${locale}` | ||
); | ||
|
||
if (!data && !error) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
if (!data) { | ||
return <Error statusCode={404} />; | ||
} | ||
|
||
return ( | ||
<> | ||
<Header | ||
subtext={ | ||
<Link href={`/movie/${data.id}`}> | ||
<a className="hover:underline">{data.title}</a> | ||
</Link> | ||
} | ||
> | ||
{intl.formatMessage(messages.fullcast)} | ||
</Header> | ||
<ul className="grid grid-cols-2 gap-6 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-7 2xl:grid-cols-8"> | ||
{data?.credits.cast.map((person) => { | ||
return ( | ||
<li | ||
key={person.id} | ||
className="col-span-1 flex flex-col text-center items-center" | ||
> | ||
<PersonCard | ||
name={person.name} | ||
personId={person.id} | ||
subName={person.character} | ||
profilePath={person.profilePath} | ||
canExpand | ||
/> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</> | ||
); | ||
}; | ||
|
||
export default MovieCast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Link from 'next/link'; | ||
import { useRouter } from 'next/router'; | ||
import React, { useContext } from 'react'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
import useSWR from 'swr'; | ||
import type { TvDetails } from '../../../../server/models/Tv'; | ||
import { LanguageContext } from '../../../context/LanguageContext'; | ||
import Error from '../../../pages/_error'; | ||
import Header from '../../Common/Header'; | ||
import LoadingSpinner from '../../Common/LoadingSpinner'; | ||
import PersonCard from '../../PersonCard'; | ||
|
||
const messages = defineMessages({ | ||
fullseriescast: 'Full Series Cast', | ||
}); | ||
|
||
const TvCast: React.FC = () => { | ||
const router = useRouter(); | ||
const intl = useIntl(); | ||
const { locale } = useContext(LanguageContext); | ||
const { data, error } = useSWR<TvDetails>( | ||
`/api/v1/tv/${router.query.tvId}?language=${locale}` | ||
); | ||
|
||
if (!data && !error) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
if (!data) { | ||
return <Error statusCode={404} />; | ||
} | ||
|
||
return ( | ||
<> | ||
<Header | ||
subtext={ | ||
<Link href={`/tv/${data.id}`}> | ||
<a className="hover:underline">{data.name}</a> | ||
</Link> | ||
} | ||
> | ||
{intl.formatMessage(messages.fullseriescast)} | ||
</Header> | ||
<ul className="grid grid-cols-2 gap-6 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-7 2xl:grid-cols-8"> | ||
{data?.credits.cast.map((person) => { | ||
return ( | ||
<li | ||
key={person.id} | ||
className="col-span-1 flex flex-col text-center items-center" | ||
> | ||
<PersonCard | ||
name={person.name} | ||
personId={person.id} | ||
subName={person.character} | ||
profilePath={person.profilePath} | ||
canExpand | ||
/> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</> | ||
); | ||
}; | ||
|
||
export default TvCast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NextPage } from 'next'; | ||
import React from 'react'; | ||
import MovieCast from '../../../components/MovieDetails/MovieCast'; | ||
|
||
const MovieCastPage: NextPage = () => { | ||
return <MovieCast />; | ||
}; | ||
|
||
export default MovieCastPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NextPage } from 'next'; | ||
import React from 'react'; | ||
import TvCast from '../../../components/TvDetails/TvCast'; | ||
|
||
const TvCastPage: NextPage = () => { | ||
return <TvCast />; | ||
}; | ||
|
||
export default TvCastPage; |