mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Now shows errors from API in the status box
This commit is contained in:
parent
d65cbe0d9a
commit
c039a67b76
4 changed files with 9 additions and 32 deletions
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class Subreddit extends React.Component {
|
|||
this.setState({ threads, loading: false })
|
||||
this.props.global.setSuccess()
|
||||
})
|
||||
.catch(this.props.global.setError)
|
||||
}
|
||||
|
||||
render () {
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue