Fix muted parents not uncollapsed (#1775)
* Fix parents not uncollapsed of router.query.commentId * Fix code comment * Use descriptive fragment name * Add cache to effect dependencies not sure if needed since also works without but probably safer to have than not
This commit is contained in:
parent
ba2cdc2275
commit
a41d077c21
|
@ -26,6 +26,7 @@ import { commentSubTreeRootId } from '@/lib/item'
|
||||||
import Pin from '@/svgs/pushpin-fill.svg'
|
import Pin from '@/svgs/pushpin-fill.svg'
|
||||||
import LinkToContext from './link-to-context'
|
import LinkToContext from './link-to-context'
|
||||||
import Boost from './boost-button'
|
import Boost from './boost-button'
|
||||||
|
import { gql, useApolloClient } from '@apollo/client'
|
||||||
|
|
||||||
function Parent ({ item, rootText }) {
|
function Parent ({ item, rootText }) {
|
||||||
const root = useRoot()
|
const root = useRoot()
|
||||||
|
@ -108,16 +109,28 @@ export default function Comment ({
|
||||||
const root = useRoot()
|
const root = useRoot()
|
||||||
const { ref: textRef, quote, quoteReply, cancelQuote } = useQuoteReply({ text: item.text })
|
const { ref: textRef, quote, quoteReply, cancelQuote } = useQuoteReply({ text: item.text })
|
||||||
|
|
||||||
|
const { cache } = useApolloClient()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const comment = cache.readFragment({
|
||||||
|
id: `Item:${router.query.commentId}`,
|
||||||
|
fragment: gql`
|
||||||
|
fragment CommentPath on Item {
|
||||||
|
path
|
||||||
|
}`
|
||||||
|
})
|
||||||
|
if (comment?.path.split('.').includes(item.id)) {
|
||||||
|
window.localStorage.setItem(`commentCollapse:${item.id}`, 'nope')
|
||||||
|
}
|
||||||
setCollapse(window.localStorage.getItem(`commentCollapse:${item.id}`) || collapse)
|
setCollapse(window.localStorage.getItem(`commentCollapse:${item.id}`) || collapse)
|
||||||
if (Number(router.query.commentId) === Number(item.id)) {
|
if (Number(router.query.commentId) === Number(item.id)) {
|
||||||
// HACK wait for other comments to collapse if they're collapsed
|
// HACK wait for other comments to uncollapse if they're collapsed
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ref.current.scrollIntoView({ behavior: 'instant', block: 'start' })
|
ref.current.scrollIntoView({ behavior: 'instant', block: 'start' })
|
||||||
ref.current.classList.add('outline-it')
|
ref.current.classList.add('outline-it')
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
}, [item.id, router.query.commentId])
|
}, [item.id, cache, router.query.commentId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (router.query.commentsViewedAt &&
|
if (router.query.commentsViewedAt &&
|
||||||
|
|
Loading…
Reference in New Issue