-
-
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): request card / recent requests
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 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,56 @@ | ||
import React from 'react'; | ||
import useSWR from 'swr'; | ||
import type { MovieDetails } from '../../../server/models/Movie'; | ||
import type { TvDetails } from '../../../server/models/Tv'; | ||
import TitleCard from '.'; | ||
|
||
interface TmdbTitleCardProps { | ||
tmdbId: number; | ||
type: 'movie' | 'tv'; | ||
} | ||
|
||
const isMovie = (movie: MovieDetails | TvDetails): movie is MovieDetails => { | ||
return (movie as MovieDetails).title !== undefined; | ||
}; | ||
|
||
const RequestCard: React.FC<TmdbTitleCardProps> = ({ tmdbId, type }) => { | ||
const url = | ||
type === 'movie' ? `/api/v1/movie/${tmdbId}` : `/api/v1/tv/${tmdbId}`; | ||
const { data: title, error } = useSWR<MovieDetails | TvDetails>(url); | ||
|
||
if (!title && !error) { | ||
return <TitleCard.Placeholder />; | ||
} | ||
|
||
if (!title) { | ||
return <TitleCard.Placeholder />; | ||
} | ||
|
||
return isMovie(title) ? ( | ||
<TitleCard | ||
id={title.id} | ||
image={title.posterPath} | ||
status={title.request?.status} | ||
summary={title.overview} | ||
title={title.title} | ||
userScore={title.voteAverage} | ||
year={title.releaseDate} | ||
mediaType={'movie'} | ||
requestId={title.request?.id} | ||
/> | ||
) : ( | ||
<TitleCard | ||
id={title.id} | ||
image={title.posterPath} | ||
status={title.request?.status} | ||
summary={title.overview} | ||
title={title.name} | ||
userScore={title.voteAverage} | ||
year={title.firstAirDate} | ||
mediaType={'tv'} | ||
requestId={title.request?.id} | ||
/> | ||
); | ||
}; | ||
|
||
export default RequestCard; |
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