fix: dataset pagination state keeps resetting when filters changed (#15268)
This commit is contained in:
parent
908a7b6c3d
commit
c9e3c8b38d
@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useRef } from 'react'
|
import { useCallback, useEffect, useRef } from 'react'
|
||||||
import useSWRInfinite from 'swr/infinite'
|
import useSWRInfinite from 'swr/infinite'
|
||||||
import { debounce } from 'lodash-es'
|
import { debounce } from 'lodash-es'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -62,21 +62,28 @@ const Datasets = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadingStateRef.current = isLoading
|
loadingStateRef.current = isLoading
|
||||||
document.title = `${t('dataset.knowledge')} - Dify`
|
document.title = `${t('dataset.knowledge')} - Dify`
|
||||||
}, [isLoading])
|
}, [isLoading, t])
|
||||||
|
|
||||||
useEffect(() => {
|
const onScroll = useCallback(
|
||||||
const onScroll = debounce(() => {
|
debounce(() => {
|
||||||
if (!loadingStateRef.current) {
|
if (!loadingStateRef.current && containerRef.current && anchorRef.current) {
|
||||||
const { scrollTop, clientHeight } = containerRef.current!
|
const { scrollTop, clientHeight } = containerRef.current
|
||||||
const anchorOffset = anchorRef.current!.offsetTop
|
const anchorOffset = anchorRef.current.offsetTop
|
||||||
if (anchorOffset - scrollTop - clientHeight < 100)
|
if (anchorOffset - scrollTop - clientHeight < 100)
|
||||||
setSize(size => size + 1)
|
setSize(size => size + 1)
|
||||||
}
|
}
|
||||||
}, 50)
|
}, 50),
|
||||||
|
[setSize],
|
||||||
|
)
|
||||||
|
|
||||||
containerRef.current?.addEventListener('scroll', onScroll)
|
useEffect(() => {
|
||||||
return () => containerRef.current?.removeEventListener('scroll', onScroll)
|
const currentContainer = containerRef.current
|
||||||
}, [])
|
currentContainer?.addEventListener('scroll', onScroll)
|
||||||
|
return () => {
|
||||||
|
currentContainer?.removeEventListener('scroll', onScroll)
|
||||||
|
onScroll.cancel()
|
||||||
|
}
|
||||||
|
}, [onScroll])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className='grid content-start grid-cols-1 gap-4 px-12 pt-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 grow shrink-0'>
|
<nav className='grid content-start grid-cols-1 gap-4 px-12 pt-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 grow shrink-0'>
|
||||||
|
Loading…
Reference in New Issue
Block a user