Clear scroll need for root post to fix jump bug
This commit is contained in:
@@ -52,6 +52,14 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
* One query to rule them all
|
* One query to rule them all
|
||||||
*/
|
*/
|
||||||
const thread = usePostThread({anchor: uri})
|
const thread = usePostThread({anchor: uri})
|
||||||
|
const anchor = useMemo(() => {
|
||||||
|
for (const item of thread.data.items) {
|
||||||
|
if (item.type === 'threadPost' && item.depth === 0) {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}, [thread.data.items])
|
||||||
|
|
||||||
const {openComposer} = useOpenComposer()
|
const {openComposer} = useOpenComposer()
|
||||||
const optimisticOnPostReply = useCallback(
|
const optimisticOnPostReply = useCallback(
|
||||||
@@ -66,35 +74,25 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
[thread],
|
[thread],
|
||||||
)
|
)
|
||||||
const onReplyToAnchor = useCallback(() => {
|
const onReplyToAnchor = useCallback(() => {
|
||||||
const anchorPost = thread.data.items.find(
|
if (anchor?.type !== 'threadPost') {
|
||||||
slice => slice.type === 'threadPost' && slice.ui.isAnchor,
|
|
||||||
)
|
|
||||||
if (anchorPost?.type !== 'threadPost') {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const post = anchorPost.value.post
|
const post = anchor.value.post
|
||||||
openComposer({
|
openComposer({
|
||||||
replyTo: {
|
replyTo: {
|
||||||
uri: anchorPost.uri,
|
uri: anchor.uri,
|
||||||
cid: post.cid,
|
cid: post.cid,
|
||||||
text: post.record.text,
|
text: post.record.text,
|
||||||
author: post.author,
|
author: post.author,
|
||||||
embed: post.embed,
|
embed: post.embed,
|
||||||
moderation: anchorPost.moderation,
|
moderation: anchor.moderation,
|
||||||
},
|
},
|
||||||
onPostSuccess: optimisticOnPostReply,
|
onPostSuccess: optimisticOnPostReply,
|
||||||
})
|
})
|
||||||
}, [thread, openComposer, optimisticOnPostReply])
|
}, [anchor, openComposer, optimisticOnPostReply])
|
||||||
|
|
||||||
const canReply = useMemo(() => {
|
const isRoot = !!anchor && anchor.value.post.record.reply === undefined
|
||||||
if (thread.state.error) return false
|
const canReply = !anchor?.value.post?.viewer?.replyDisabled
|
||||||
for (const item of thread.data.items) {
|
|
||||||
if (item.type === 'threadPost' && item.depth === 0) {
|
|
||||||
return !item.value.post?.viewer?.replyDisabled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}, [thread.state.error, thread.data.items])
|
|
||||||
const [maxParentCount, setMaxParentCount] = useState(PARENT_CHUNK_SIZE)
|
const [maxParentCount, setMaxParentCount] = useState(PARENT_CHUNK_SIZE)
|
||||||
const [maxChildrenCount, setMaxChildrenCount] = useState(CHILDREN_CHUNK_SIZE)
|
const [maxChildrenCount, setMaxChildrenCount] = useState(CHILDREN_CHUNK_SIZE)
|
||||||
const totalParentCount = useRef(0) // recomputed below
|
const totalParentCount = useRef(0) // recomputed below
|
||||||
@@ -123,7 +121,7 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
* this is always true. And when a user changes thread parameters, we also
|
* this is always true. And when a user changes thread parameters, we also
|
||||||
* manually set this to true.
|
* manually set this to true.
|
||||||
*/
|
*/
|
||||||
const shouldHandleScroll = useRef(true)
|
const shouldHandleScroll = useRef(!isRoot)
|
||||||
/**
|
/**
|
||||||
* Called any time the content size of the list changes, _just_ before paint.
|
* Called any time the content size of the list changes, _just_ before paint.
|
||||||
*
|
*
|
||||||
@@ -144,8 +142,6 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
const anchorOffsetTop = anchor.getBoundingClientRect().top
|
const anchorOffsetTop = anchor.getBoundingClientRect().top
|
||||||
const headerHeight = header.getBoundingClientRect().height
|
const headerHeight = header.getBoundingClientRect().height
|
||||||
|
|
||||||
console.log({anchorOffsetTop})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* `deferParents` is `true` on a cold load, and always reset to
|
* `deferParents` is `true` on a cold load, and always reset to
|
||||||
* `true` when params change via `prepareForParamsUpdate`.
|
* `true` when params change via `prepareForParamsUpdate`.
|
||||||
@@ -181,8 +177,15 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
* to ensure this doesn't run again until scroll handling is requested
|
* to ensure this doesn't run again until scroll handling is requested
|
||||||
* again via `shouldHandleScroll.current === true` and a params
|
* again via `shouldHandleScroll.current === true` and a params
|
||||||
* change via `prepareForParamsUpdate`.
|
* change via `prepareForParamsUpdate`.
|
||||||
|
*
|
||||||
|
* The `isRoot` here is needed because if we're looking at the anchor
|
||||||
|
* post, this handler will not fire after `deferParents` is set to
|
||||||
|
* `false`, since there are no parents to render above it. In this case,
|
||||||
|
* we want to make sure `shouldHandleScroll` is set to `false` so that
|
||||||
|
* subsequent size changes unrelated to a params change (like pagination)
|
||||||
|
* do not affect scroll.
|
||||||
*/
|
*/
|
||||||
if (!deferParents) shouldHandleScroll.current = false
|
if (!deferParents || isRoot) shouldHandleScroll.current = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user