diff --git a/static/src/js/components/index/project-image.js b/static/src/js/components/index/project-image.js index bed2190..c4f6f3c 100644 --- a/static/src/js/components/index/project-image.js +++ b/static/src/js/components/index/project-image.js @@ -11,15 +11,19 @@ export default class ProjectImage extends React.Component { }; } componentDidMount() { + if (!this.props.data.link || this.props.data.link === '') { + return; + } if (this.props.data.link.startsWith('#')) { this.setState({url: this.props.data.link}); } else { - const args = this.props.data.args || false; - Reverser(this.props.data.link, args) - .then(function (url) { + let args; + if (this.props.data.args) { + args = [this.props.data.args]; + } + Reverser(this.props.data.link, args, function (url) { this.setState({ url }); - }.bind(this)) - .catch(console.log); + }.bind(this)); } } diff --git a/static/src/js/components/navbar/item.js b/static/src/js/components/navbar/item.js index b01f299..059066e 100644 --- a/static/src/js/components/navbar/item.js +++ b/static/src/js/components/navbar/item.js @@ -18,11 +18,9 @@ export default class Item extends React.Component { if (this.props.href) { this.setState({url: this.props.href}); } else { - Reverser(this.props.ident, this.props.args) - .then(function (url) { + Reverser(this.props.ident, this.props.args, function (url) { this.setState({ url }); - }.bind(this)) - .catch(console.log); + }.bind(this)); } } render() { diff --git a/static/src/js/helpers/reverser.js b/static/src/js/helpers/reverser.js index 76f9b57..9baf18f 100644 --- a/static/src/js/helpers/reverser.js +++ b/static/src/js/helpers/reverser.js @@ -1,4 +1,4 @@ -export default function Reverser(ident, args) { +export default function Reverser(ident, args, onSuccess) { let body = {}; if (ident) { body.ident = ident; @@ -6,21 +6,28 @@ export default function Reverser(ident, args) { body.args = args; } } - body = JSON.stringify(body); - return fetch('/reverse/', { - method: 'post', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body - }).then(function (response) { - if (response.status === 302) { - return response; - } else { - var error = new Error(response.statusText); - error.response = response; - throw error; - } - }).then((response) => response.json()); + if (body !== {}) { + body = JSON.stringify(body); + fetch('/reverse/', { + method: 'post', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body + }).then(function (response) { + if (response.status === 302) { + return response; + } else { + var error = new Error(response.statusText); + error.response = response; + throw error; + } + }).then( + (response) => response.json() + ).then(onSuccess) + .catch(function (err) { + console.log(err); + }); + } }