From ed46bdcf5e3623e069f5c41eb8013cda5629f815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Tue, 18 Apr 2017 14:32:40 +0200 Subject: [PATCH] Double check props before exploring movies / shows --- .../js/components/list/explorerOptions.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/public/js/components/list/explorerOptions.js b/src/public/js/components/list/explorerOptions.js index d71e0ea..f4ed65b 100644 --- a/src/public/js/components/list/explorerOptions.js +++ b/src/public/js/components/list/explorerOptions.js @@ -11,9 +11,11 @@ export default class ExplorerOptions extends React.Component { // Check if the options are present if (Object.keys(this.props.options).length === 0) { // Fetch options - this.props.fetchOptions(); + props.fetchOptions(); // 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 { source = this.props.params.source; category = this.props.params.category; @@ -42,12 +44,19 @@ export default class ExplorerOptions extends React.Component { this.setState({ selectedCategory: 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) { // Check props - if (!nextProps.params.source - || !nextProps.params.category - || (nextProps.params.source === "") - || (nextProps.params.category === "")) { + if (!this.propsValid(nextProps)) { return }