Double check props before exploring movies / shows

This commit is contained in:
Grégoire Delattre 2017-04-18 14:32:40 +02:00
parent a3a9d65f9b
commit ed46bdcf5e

View File

@ -11,9 +11,11 @@ export default class ExplorerOptions extends React.Component {
// Check if the options are present // Check if the options are present
if (Object.keys(this.props.options).length === 0) { if (Object.keys(this.props.options).length === 0) {
// Fetch options // Fetch options
this.props.fetchOptions(); props.fetchOptions();
// Explore // Explore
this.props.explore(this.props.params.source, this.props.params.category); if (this.propsValid(props)) {
props.explore(props.params.source, props.params.category);
}
} else { } else {
source = this.props.params.source; source = this.props.params.source;
category = this.props.params.category; category = this.props.params.category;
@ -42,12 +44,19 @@ export default class ExplorerOptions extends React.Component {
this.setState({ selectedCategory: event.target.value }); this.setState({ selectedCategory: event.target.value });
this.props.router.push(`/${this.props.type}/explore/${this.state.selectedSource}/${event.target.value}`); this.props.router.push(`/${this.props.type}/explore/${this.state.selectedSource}/${event.target.value}`);
} }
propsValid(props) {
if (!props.params
|| !props.params.source
|| !props.params.category
|| (props.params.source === "")
|| (props.params.category === "")) {
return false
}
return true;
}
componentWillUpdate(nextProps, nextState) { componentWillUpdate(nextProps, nextState) {
// Check props // Check props
if (!nextProps.params.source if (!this.propsValid(nextProps)) {
|| !nextProps.params.category
|| (nextProps.params.source === "")
|| (nextProps.params.category === "")) {
return return
} }