wait for comments to collapse before scrolling

This commit is contained in:
keyan 2023-06-12 16:03:32 -05:00
parent ab3b24a072
commit 5958875f1e
1 changed files with 11 additions and 8 deletions

View File

@ -99,15 +99,18 @@ export default function Comment ({
const root = useRoot()
useEffect(() => {
if (Number(router.query.commentId) === Number(item.id)) {
ref.current.scrollIntoView()
ref.current.classList.add('flash-it')
router.replace({
pathname: router.pathname,
query: { id: router.query.id }
}, undefined, { scroll: false })
}
setCollapse(localStorage.getItem(`commentCollapse:${item.id}`) || collapse)
if (Number(router.query.commentId) === Number(item.id)) {
// HACK wait for other comments to collapse if they're collapsed
setTimeout(() => {
ref.current.scrollIntoView()
ref.current.classList.add('flash-it')
router.replace({
pathname: router.pathname,
query: { id: router.query.id }
}, undefined, { scroll: false })
}, 20)
}
}, [item])
const bottomedOut = depth === COMMENT_DEPTH_LIMIT