diff --git a/static/src/js/components/index/project-image.js b/static/src/js/components/index/project-image.js index 0c5d734..60a24f0 100644 --- a/static/src/js/components/index/project-image.js +++ b/static/src/js/components/index/project-image.js @@ -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); }); } diff --git a/static/src/js/helpers/reverser.js b/static/src/js/helpers/reverser.js new file mode 100644 index 0000000..0c6f502 --- /dev/null +++ b/static/src/js/helpers/reverser.js @@ -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()); +}