-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TV Seasons and Episodes support added
- Loading branch information
Showing
5 changed files
with
249 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from "react"; | ||
import { Calendar } from "react-bytesize-icons"; | ||
import Img from "react-cool-img"; | ||
import { Link } from "react-router-dom"; | ||
import { COVER_URL, FALLBACK_IMAGE } from "../../constants"; | ||
|
||
const EpisodesList = ({ showName, tvId, seasonNumber, episodes }) => | ||
episodes && episodes.length > 0 ? ( | ||
<article> | ||
<h6>Episodes</h6> | ||
<div className="row"> | ||
{episodes.map((episode, i) => { | ||
const { name, overview, episode_number, still_path, air_date } = | ||
episode; | ||
return ( | ||
<Link | ||
key={i} | ||
to={`/tv/${tvId}/${showName}/seasons/${seasonNumber}/episodes/${episode_number}`} | ||
className="col-sm-12 col-xs-12" | ||
> | ||
<div className="d-flex rounded-card"> | ||
<div className="py-2 px-2"> | ||
<Img | ||
src={`${COVER_URL + still_path}`} | ||
error={FALLBACK_IMAGE} | ||
className="rounded" | ||
width={144} | ||
alt={name} | ||
/> | ||
</div> | ||
<div className="flex-1-1-a py-2 px-3"> | ||
<h6 className="d-flex align-items-center"> | ||
<span className="mr-2">{name}</span> | ||
<span className="flex-shrink-0 pill px-3 py-1 mr-2 d-flex align-items-center"> | ||
<Calendar | ||
className="align-top mr-2" | ||
width="14" | ||
height="14" | ||
strokeWidth="2" | ||
/> | ||
<span>Aired {air_date}</span> | ||
</span> | ||
<small className="flex-shrink-0 ml-auto text-muted"> | ||
Episode {episode_number} | ||
</small> | ||
</h6> | ||
<p className="m-0">{overview}</p> | ||
</div> | ||
</div> | ||
</Link> | ||
); | ||
})} | ||
</div> | ||
</article> | ||
) : ( | ||
"" | ||
); | ||
|
||
export default EpisodesList; |
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,171 @@ | ||
import React, { Component } from "react"; | ||
import { getItemTrailer } from "../../utils"; | ||
import theMovieDb from "themoviedb-javascript-library"; | ||
import isEmpty from "lodash/isEmpty"; | ||
import NoDataFound from "../../components/shared/NoDataFound"; | ||
import Loader from "../../components/shared/Loader"; | ||
import Player from "../../components/item/Player"; | ||
import ItemDetails from "../../components/item/ItemDetails"; | ||
import GA from "react-ga"; | ||
|
||
class EpisodeItem extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
playing: false, | ||
itemDetails: {}, | ||
loading: true, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const { id, number, episode } = this.props.match.params; | ||
this.getItemById(id, number, episode); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
const { id, number, episode } = this.props.match.params; | ||
if (id !== prevProps.match.params.id) { | ||
this.getItemById(id, number, episode); | ||
} | ||
} | ||
|
||
getItemById = (id, season_number, episode_number) => { | ||
theMovieDb.tvEpisodes.getById( | ||
{ | ||
id, | ||
season_number, | ||
episode_number, | ||
append_to_response: | ||
"videos,recommendations,images&include_image_language=en,null", | ||
}, | ||
(data) => this.successCB(data, id, season_number, episode_number), | ||
this.errorCB | ||
); | ||
}; | ||
|
||
successCB = (data, id, season_number, episode_number) => { | ||
const fetchedData = JSON.parse(data); | ||
this.setState( | ||
{ | ||
loading: false, | ||
itemDetails: fetchedData, | ||
}, | ||
() => { | ||
theMovieDb.tv.getCredits( | ||
{ id, season_number, episode_number }, | ||
this.creditsSuccessCB, | ||
this.errorCB | ||
); | ||
} | ||
); | ||
}; | ||
|
||
errorCB = (data) => { | ||
if (data) { | ||
this.setState({ | ||
loading: false, | ||
tmdbResponse: JSON.parse(data).status_message, | ||
}); | ||
} else { | ||
this.setState({ | ||
loading: false, | ||
itemDetails: {}, | ||
}); | ||
} | ||
}; | ||
|
||
creditsSuccessCB = (data) => { | ||
const { itemDetails } = this.state; | ||
const fetchedData = JSON.parse(data); | ||
this.setState({ | ||
itemDetails: { ...itemDetails, casts: fetchedData }, | ||
}); | ||
}; | ||
|
||
handlePlayerState = () => { | ||
const { playing } = this.state; | ||
this.setState( | ||
{ | ||
playing: !playing, | ||
}, | ||
() => { | ||
this.state.playing && | ||
GA.event({ | ||
category: "Player", | ||
action: "Play trailer for tv episode", | ||
}); | ||
} | ||
); | ||
}; | ||
|
||
render() { | ||
const { playing, itemDetails, tmdbResponse, loading } = this.state; | ||
const { | ||
name, | ||
status, | ||
overview, | ||
vote_average, | ||
first_air_date, | ||
still_path, | ||
backdrop_path, | ||
genres, | ||
homepage, | ||
budget, | ||
revenue, | ||
runtime, | ||
imdb_id, | ||
videos, | ||
images, | ||
production_companies, | ||
} = itemDetails; | ||
|
||
if (!isEmpty(itemDetails)) { | ||
var { stills } = images; | ||
var { results } = videos; | ||
} | ||
|
||
if (!isEmpty(itemDetails.casts)) { | ||
var { cast, crew } = itemDetails.casts; | ||
} | ||
|
||
return !isEmpty(itemDetails) ? ( | ||
<> | ||
{results.length > 0 && ( | ||
<Player | ||
videoId={getItemTrailer(results)} | ||
poster={backdrop_path ? backdrop_path : still_path} | ||
title={name} | ||
playing={playing} | ||
handlePlayerState={this.handlePlayerState} | ||
/> | ||
)} | ||
<ItemDetails | ||
id={this.props.match.params.id} | ||
title={name} | ||
release={first_air_date} | ||
genres={genres} | ||
runtime={runtime} | ||
overview={overview} | ||
rating={vote_average} | ||
poster={still_path} | ||
status={status} | ||
link={homepage} | ||
budget={budget} | ||
revenue={revenue} | ||
imdb={imdb_id} | ||
backdrops={stills} | ||
cast={cast} | ||
crew={crew} | ||
productionCompanies={production_companies} | ||
/> | ||
</> | ||
) : tmdbResponse ? ( | ||
<NoDataFound alignCenter spaceTop message={tmdbResponse} /> | ||
) : loading ? ( | ||
<Loader spaceTop /> | ||
) : null; | ||
} | ||
} | ||
|
||
export default EpisodeItem; |
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