Externalised reverser into helper function
This commit is contained in:
parent
37f5e1cfef
commit
36ff669a00
2 changed files with 23 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
|||
import React from 'react';
|
||||
import Reverser from '../../helpers/reverser';
|
||||
var ReactBootstrap = require('react-bootstrap');
|
||||
var Col = ReactBootstrap.Col;
|
||||
|
||||
|
@ -13,28 +14,11 @@ export default class ProjectImage extends React.Component {
|
|||
if (this.props.data.link.startsWith('#')) {
|
||||
return;
|
||||
}
|
||||
fetch('/reverse/', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
ident: this.props.data.link,
|
||||
})
|
||||
}).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(function (url) {
|
||||
Reverser(this.props.data.link)
|
||||
.then(function (url) {
|
||||
this.setState({ url });
|
||||
}.bind(this)).catch(function (error) {
|
||||
}.bind(this))
|
||||
.catch(function (error) {
|
||||
console.log('Got this error:', error);
|
||||
});
|
||||
}
|
||||
|
|
18
static/src/js/helpers/reverser.js
Normal file
18
static/src/js/helpers/reverser.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
export default function Reverser(ident) {
|
||||
return fetch('/reverse/', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ident})
|
||||
}).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());
|
||||
}
|
Reference in a new issue