| | |
| | | 'use client' |
| | | |
| | | import { useCallback, useEffect, useRef } from 'react' |
| | | import { useEffect, useRef } from 'react' |
| | | import useSWRInfinite from 'swr/infinite' |
| | | import { debounce } from 'lodash-es' |
| | | import { useTranslation } from 'react-i18next' |
| | |
| | | useEffect(() => { |
| | | loadingStateRef.current = isLoading |
| | | document.title = `${t('dataset.knowledge')} - Dify` |
| | | }, [isLoading, t]) |
| | | }, [isLoading]) |
| | | |
| | | const onScroll = useCallback( |
| | | debounce(() => { |
| | | if (!loadingStateRef.current && containerRef.current && anchorRef.current) { |
| | | const { scrollTop, clientHeight } = containerRef.current |
| | | const anchorOffset = anchorRef.current.offsetTop |
| | | useEffect(() => { |
| | | const onScroll = debounce(() => { |
| | | if (!loadingStateRef.current) { |
| | | const { scrollTop, clientHeight } = containerRef.current! |
| | | const anchorOffset = anchorRef.current!.offsetTop |
| | | if (anchorOffset - scrollTop - clientHeight < 100) |
| | | setSize(size => size + 1) |
| | | } |
| | | }, 50), |
| | | [setSize], |
| | | ) |
| | | }, 50) |
| | | |
| | | useEffect(() => { |
| | | const currentContainer = containerRef.current |
| | | currentContainer?.addEventListener('scroll', onScroll) |
| | | return () => { |
| | | currentContainer?.removeEventListener('scroll', onScroll) |
| | | onScroll.cancel() |
| | | } |
| | | }, [onScroll]) |
| | | containerRef.current?.addEventListener('scroll', onScroll) |
| | | return () => containerRef.current?.removeEventListener('scroll', onScroll) |
| | | }, []) |
| | | |
| | | return ( |
| | | <nav className='grid shrink-0 grow grid-cols-1 content-start gap-4 px-12 pt-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'> |
| | | <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'> |
| | | { isCurrentWorkspaceEditor && <NewDatasetCard ref={anchorRef} /> } |
| | | {data?.map(({ data: datasets }) => datasets.map(dataset => ( |
| | | <DatasetCard key={dataset.id} dataset={dataset} onSuccess={mutate} />), |