diff --git a/src/api/pushshift/index.js b/src/api/pushshift/index.js index 3f269ff..96e2b05 100644 --- a/src/api/pushshift/index.js +++ b/src/api/pushshift/index.js @@ -1,8 +1,7 @@ import { toBase10, toBase36 } from '../../utils' -const baseURL = 'https://elastic.pushshift.io' -const postURL = `${baseURL}/rs/submissions/_search?source=` -const commentURL = `${baseURL}/rc/comments/_search?source=` +const postURL = 'https://elastic.pushshift.io/rs/submissions/_search?source=' +const commentURL = 'https://elastic.pushshift.io/rc/comments/_search?source=' export const getPost = threadID => { const elasticQuery = { @@ -23,19 +22,6 @@ export const getPost = threadID => { .catch(() => { throw new Error('Could not get removed post') }) } -// export const getComments = threadID => ( -// fetch(`https://api.pushshift.io/reddit/comment/search?link_id=${threadID}&limit=10000`) -// .then(json) -// .then(data => data.data) -// .then(comments => { -// comments.forEach(comment => { -// comment.link_id = comment.link_id.split('_')[1] -// comment.parent_id = comment.parent_id.split('_')[1] -// }) -// return comments -// }) -// ) - export const getComments = threadID => { const elasticQuery = { query: { diff --git a/src/pages/subreddit/index.js b/src/pages/subreddit/index.js index 27e2de0..67c6fdb 100644 --- a/src/pages/subreddit/index.js +++ b/src/pages/subreddit/index.js @@ -42,6 +42,7 @@ class Subreddit extends React.Component { this.setState({ threads, loading: false }) this.props.global.setSuccess() }) + .catch(this.props.global.setError) } render () { diff --git a/src/pages/thread/index.js b/src/pages/thread/index.js index 68d89c0..959e7d9 100644 --- a/src/pages/thread/index.js +++ b/src/pages/thread/index.js @@ -39,7 +39,7 @@ class Thread extends React.Component { }) } }) - .catch(error => console.log(error)) + .catch(this.props.global.setError) // Get comment ids from pushshift getPushshiftComments(threadID) @@ -88,6 +88,7 @@ class Thread extends React.Component { loadingComments: false }) }) + .catch(this.props.global.setError) } render () { diff --git a/src/state/index.js b/src/state/index.js index 1173b4e..04e418e 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -44,21 +44,10 @@ class GlobalState extends Container { this.setState({commentFilter: filterType}) } - setError (text) { - this.setState({statusText: text, statusImage: '/images/error.png'}) - } - - setSuccess () { - this.setState({statusText: '', statusImage: '/images/success.png'}) - } - - setLoading (text) { - this.setState({statusText: text, statusImage: '/images/loading.gif'}) - } - - clearStatus () { - this.setState({statusText: '', statusImage: undefined}) - } + setSuccess = () => this.setState({statusText: '', statusImage: '/images/success.png'}) + setLoading = (text) => this.setState({statusText: text, statusImage: '/images/loading.gif'}) + setError = (error) => this.setState({statusText: error.message, statusImage: '/images/error.png'}) + clearStatus = () => this.setState({statusText: '', statusImage: undefined}) } // A redux-like connect function for Unstated