error handling if a requested tvshow item doesn't exist
This commit is contained in:
parent
da07dc04bd
commit
cfcfde6e42
@ -15,6 +15,8 @@ interface Props extends RouteComponentProps<{id: string}> {}
|
|||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
|
error: number;
|
||||||
|
Showname: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Episode {
|
interface Episode {
|
||||||
@ -24,28 +26,46 @@ interface Episode {
|
|||||||
Episode: number;
|
Episode: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EpisodeData {
|
||||||
|
error: number;
|
||||||
|
episodes: Episode[];
|
||||||
|
ShowName: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class EpisodePage extends React.Component<Props, State> {
|
export class EpisodePage extends React.Component<Props, State> {
|
||||||
episodes: Episode[] = [];
|
episodes: Episode[] = [];
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
loaded: false
|
loaded: false,
|
||||||
|
error: 0,
|
||||||
|
Showname: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
callAPI(APINode.TVShow, {action: 'getEpisodes', ShowID: parseInt(this.props.match.params.id, 10)}, (episodes: Episode[]) => {
|
callAPI(APINode.TVShow, {action: 'getEpisodes', ShowID: parseInt(this.props.match.params.id, 10)}, (data: EpisodeData) => {
|
||||||
this.episodes = episodes;
|
if (data.error !== 0) {
|
||||||
this.setState({loaded: true});
|
this.setState({error: data.error, loaded: true});
|
||||||
|
} else {
|
||||||
|
this.episodes = data.episodes;
|
||||||
|
this.setState({loaded: true, Showname: data.ShowName});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
|
// check if content is loaded
|
||||||
if (!this.state.loaded) {
|
if (!this.state.loaded) {
|
||||||
return <>loading...</>;
|
return <>loading...</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if there is an error to display
|
||||||
|
if (this.state.error !== 0) {
|
||||||
|
return <>Error code: {this.state.error}</>;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageTitle title='TV Shows' subtitle='' />
|
<PageTitle title={this.state.Showname} subtitle={this.episodes.length + ' Episodes'} />
|
||||||
<SideBar>
|
<SideBar>
|
||||||
<SideBarTitle>Infos:</SideBarTitle>
|
<SideBarTitle>Infos:</SideBarTitle>
|
||||||
<Line />
|
<Line />
|
||||||
|
Loading…
Reference in New Issue
Block a user