Fix some minor (mostly display) context bugs

This commit is contained in:
Christopher Gurnee 2022-05-16 20:53:14 +00:00
parent 07d4863c7a
commit d35f7e7bf0
2 changed files with 16 additions and 9 deletions

View file

@ -142,10 +142,11 @@ const commentSection = (props) => {
}
}
lastTotal = total
lastRoot = root
lastFilter = commentFilter
lastSort = commentSort
lastTotal = total
lastRoot = root
lastContext = context
lastFilter = commentFilter
lastSort = commentSort
console.timeEnd('Build comment tree')
props.setMoreContextAvail(commentTree.length > 0 && commentTree[0].parent_id != commentTree[0].link_id)

View file

@ -371,7 +371,7 @@ class Thread extends React.Component {
// Check if the context query parameter has changed
if (commentID) {
const context = parseInt((new URLSearchParams(this.props.location.search)).get('context')) || 0
const context = Math.max(parseInt((new URLSearchParams(this.props.location.search)).get('context')) || 0, 0)
if (context > this.state.context) {
this.setState({reloadingComments: true})
this.props.global.setLoading('Loading comments...')
@ -383,9 +383,11 @@ class Thread extends React.Component {
this.props.global.setSuccess()
this.setState({loadingComments: false, reloadingComments: false})
})
} else if (context >= 0 && context != this.state.context)
} else if (context != this.state.context)
this.setState({ context })
}
} else if (0 != this.state.context)
this.setState({ context: 0 })
} // end of "If we're not already downloading comments, check to see if we need to start"
// Handle any requested scrolling
@ -575,6 +577,7 @@ class Thread extends React.Component {
// Makes a best-effort attempt to retrieve context# ancestors of the current commentID.
// Returns a Promise which resolves with the number retrieved, or rejects with undefined.
// (Each code path below must setState({ context }) to avoid an infinite loop.)
getContext (context) {
const { params } = this.props.match
const { pushshiftCommentLookup } = this.state
@ -585,12 +588,15 @@ class Thread extends React.Component {
.then(pushshiftComments => {
if (ids.length)
console.log('Pushshift:', pushshiftComments.length, 'comments')
this.setState({ context })
this.setState({ context }) // Displays the retrieved context
pushshiftComments.forEach(comment => pushshiftCommentLookup.set(comment.id, comment))
return this.compareAndUpdateComments(redditComments)
})
})
.catch(e => console.error(e))
.catch(e => {
console.error(e)
this.setState({ context })
})
}
componentWillUnmount () {