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() {
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));
}
}

View file

@ -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() {

View file

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