Scrolling still broken
This commit is contained in:
@@ -49,8 +49,15 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
setTreeViewEnabled,
|
setTreeViewEnabled,
|
||||||
} = useThreadPreferences()
|
} = useThreadPreferences()
|
||||||
|
|
||||||
const {isFetching, error, data, refetch, insertReplies, showHiddenReplies} =
|
const {
|
||||||
usePostThread({
|
isFetching,
|
||||||
|
isPlaceholderData,
|
||||||
|
error,
|
||||||
|
data,
|
||||||
|
refetch,
|
||||||
|
insertReplies,
|
||||||
|
showHiddenReplies,
|
||||||
|
} = usePostThread({
|
||||||
enabled: isThreadPreferencesLoaded,
|
enabled: isThreadPreferencesLoaded,
|
||||||
params: {
|
params: {
|
||||||
anchor: uri,
|
anchor: uri,
|
||||||
@@ -114,11 +121,11 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
const anchorOffsetTop = anchorElement.getBoundingClientRect().top
|
const anchorOffsetTop = anchorElement.getBoundingClientRect().top
|
||||||
const headerHeight = headerElement.getBoundingClientRect().height
|
const headerHeight = headerElement.getBoundingClientRect().height
|
||||||
const scrollPosition = anchorOffsetTop - headerHeight
|
const scrollPosition = anchorOffsetTop - headerHeight
|
||||||
console.log({
|
// console.log({
|
||||||
anchorOffsetTop,
|
// anchorOffsetTop,
|
||||||
headerHeight,
|
// headerHeight,
|
||||||
scrollPosition,
|
// scrollPosition,
|
||||||
})
|
// })
|
||||||
/*
|
/*
|
||||||
* If scroll position is negative, it means the anchor post is above the
|
* If scroll position is negative, it means the anchor post is above the
|
||||||
* top of the screen, meaning the user scrolled the list. In that case,
|
* top of the screen, meaning the user scrolled the list. In that case,
|
||||||
@@ -151,11 +158,14 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
const hasExhaustedReplies = useRef(false)
|
const hasExhaustedReplies = useRef(false)
|
||||||
|
|
||||||
const onStartReached = () => {
|
const onStartReached = () => {
|
||||||
|
// console.log('onStartReached')
|
||||||
|
if (isFetching) return
|
||||||
// limit to 100
|
// limit to 100
|
||||||
setMaxParentCount(n => Math.min(100, n + PARENT_CHUNK_SIZE))
|
setMaxParentCount(n => Math.min(100, n + PARENT_CHUNK_SIZE))
|
||||||
}
|
}
|
||||||
|
|
||||||
const onEndReached = () => {
|
const onEndReached = () => {
|
||||||
|
// console.log('onEndReached')
|
||||||
if (isFetching) return
|
if (isFetching) return
|
||||||
// prevent any state mutations if we know we're done
|
// prevent any state mutations if we know we're done
|
||||||
if (hasExhaustedReplies.current) return
|
if (hasExhaustedReplies.current) return
|
||||||
@@ -197,12 +207,13 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalRepliesCount < maxRepliesCount) {
|
// TODO should really just count these during traversal, can remove isPlaceholder data after that
|
||||||
|
if (maxRepliesCount > totalRepliesCount && !isPlaceholderData) {
|
||||||
hasExhaustedReplies.current = true
|
hasExhaustedReplies.current = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}, [data, deferParents, maxParentCount, maxRepliesCount])
|
}, [data, deferParents, maxParentCount, maxRepliesCount, isPlaceholderData])
|
||||||
|
|
||||||
const renderItem = ({item, index}: {item: ThreadItem; index: number}) => {
|
const renderItem = ({item, index}: {item: ThreadItem; index: number}) => {
|
||||||
if (item.type === 'threadPost') {
|
if (item.type === 'threadPost') {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export function usePostThread({
|
|||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
enabled,
|
enabled,
|
||||||
queryKey,
|
queryKey,
|
||||||
gcTime: 0,
|
// gcTime: 0, // TODO faster if we let it cache
|
||||||
async queryFn(ctx) {
|
async queryFn(ctx) {
|
||||||
const {data} = await wait(
|
const {data} = await wait(
|
||||||
400,
|
400,
|
||||||
|
|||||||
Reference in New Issue
Block a user