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,21 +6,28 @@ export default function Reverser(ident, args) {
body.args = args; body.args = args;
} }
} }
body = JSON.stringify(body); if (body !== {}) {
return fetch('/reverse/', { body = JSON.stringify(body);
method: 'post', fetch('/reverse/', {
headers: { method: 'post',
'Accept': 'application/json', headers: {
'Content-Type': 'application/json' 'Accept': 'application/json',
}, 'Content-Type': 'application/json'
body },
}).then(function (response) { body
if (response.status === 302) { }).then(function (response) {
return response; if (response.status === 302) {
} else { return response;
var error = new Error(response.statusText); } else {
error.response = response; var error = new Error(response.statusText);
throw error; error.response = response;
} throw error;
}).then((response) => response.json()); }
}).then(
(response) => response.json()
).then(onSuccess)
.catch(function (err) {
console.log(err);
});
}
} }