1
Fork 0

Fixed reverser.

This commit is contained in:
Jake Howard 2016-01-30 16:21:16 +00:00
parent 9d0e73622c
commit 3d3a6e853a
3 changed files with 36 additions and 27 deletions

View file

@ -11,15 +11,19 @@ export default class ProjectImage extends React.Component {
}; };
} }
componentDidMount() { componentDidMount() {
if (!this.props.data.link || this.props.data.link === '') {
return;
}
if (this.props.data.link.startsWith('#')) { if (this.props.data.link.startsWith('#')) {
this.setState({url: this.props.data.link}); this.setState({url: this.props.data.link});
} else { } else {
const args = this.props.data.args || false; let args;
Reverser(this.props.data.link, args) if (this.props.data.args) {
.then(function (url) { args = [this.props.data.args];
}
Reverser(this.props.data.link, args, function (url) {
this.setState({ url }); this.setState({ url });
}.bind(this)) }.bind(this));
.catch(console.log);
} }
} }

View file

@ -18,11 +18,9 @@ export default class Item extends React.Component {
if (this.props.href) { if (this.props.href) {
this.setState({url: this.props.href}); this.setState({url: this.props.href});
} else { } else {
Reverser(this.props.ident, this.props.args) Reverser(this.props.ident, this.props.args, function (url) {
.then(function (url) {
this.setState({ url }); this.setState({ url });
}.bind(this)) }.bind(this));
.catch(console.log);
} }
} }
render() { render() {

View file

@ -1,4 +1,4 @@
export default function Reverser(ident, args) { export default function Reverser(ident, args, onSuccess) {
let body = {}; let body = {};
if (ident) { if (ident) {
body.ident = ident; body.ident = ident;
@ -6,8 +6,9 @@ export default function Reverser(ident, args) {
body.args = args; body.args = args;
} }
} }
if (body !== {}) {
body = JSON.stringify(body); body = JSON.stringify(body);
return fetch('/reverse/', { fetch('/reverse/', {
method: 'post', method: 'post',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
@ -22,5 +23,11 @@ export default function Reverser(ident, args) {
error.response = response; error.response = response;
throw error; throw error;
} }
}).then((response) => response.json()); }).then(
(response) => response.json()
).then(onSuccess)
.catch(function (err) {
console.log(err);
});
}
} }