mirror of https://github.com/langgenius/dify.git
refactor: standardize naming for load more handlers and navigation items across components
This commit is contained in:
parent
56b66b8a57
commit
a008c04331
|
|
@ -57,7 +57,7 @@ const AppNav = () => {
|
|||
{ revalidateFirstPage: false },
|
||||
)
|
||||
|
||||
const handleLoadmore = useCallback(() => {
|
||||
const handleLoadMore = useCallback(() => {
|
||||
setSize(size => size + 1)
|
||||
}, [setSize])
|
||||
|
||||
|
|
@ -123,10 +123,10 @@ const AppNav = () => {
|
|||
activeSegment={['apps', 'app']}
|
||||
link='/apps'
|
||||
curNav={appDetail}
|
||||
navs={navItems}
|
||||
navigationItems={navItems}
|
||||
createText={t('common.menus.newApp')}
|
||||
onCreate={openModal}
|
||||
onLoadmore={handleLoadmore}
|
||||
onLoadMore={handleLoadMore}
|
||||
/>
|
||||
<CreateAppModal
|
||||
show={showNewAppDialog}
|
||||
|
|
|
|||
|
|
@ -36,28 +36,34 @@ const DatasetNav = () => {
|
|||
const { data: datasetsData, setSize } = useSWRInfinite(datasetId ? getKey : () => null, fetchDatasets, { revalidateFirstPage: false, revalidateAll: true })
|
||||
const datasetItems = flatten(datasetsData?.map(datasetData => datasetData.data))
|
||||
|
||||
const handleLoadmore = useCallback(() => {
|
||||
const handleLoadMore = useCallback(() => {
|
||||
setSize(size => size + 1)
|
||||
}, [setSize])
|
||||
|
||||
return (
|
||||
<Nav
|
||||
isApp={false}
|
||||
icon={<RiBook2Line className='h-4 w-4' />}
|
||||
activeIcon={<RiBook2Fill className='h-4 w-4' />}
|
||||
text={t('common.menus.datasets')}
|
||||
activeSegment='datasets'
|
||||
link='/datasets'
|
||||
curNav={currentDataset as Omit<NavItem, 'link'>}
|
||||
navs={datasetItems.map(dataset => ({
|
||||
curNav={currentDataset && {
|
||||
id: currentDataset.id,
|
||||
name: currentDataset.name,
|
||||
icon: currentDataset.icon_info.icon,
|
||||
icon_background: currentDataset.icon_info.icon_background,
|
||||
} as Omit<NavItem, 'link'>}
|
||||
navigationItems={datasetItems.map(dataset => ({
|
||||
id: dataset.id,
|
||||
name: dataset.name,
|
||||
link: dataset.provider === 'external' ? `/datasets/${dataset.id}/hitTesting` : `/datasets/${dataset.id}/documents`,
|
||||
icon: dataset.icon,
|
||||
icon_background: dataset.icon_background,
|
||||
icon: dataset.icon_info.icon,
|
||||
icon_background: dataset.icon_info.icon_background,
|
||||
})) as NavItem[]}
|
||||
createText={t('common.menus.newDataset')}
|
||||
onCreate={() => router.push('/datasets/create')}
|
||||
onLoadmore={handleLoadmore}
|
||||
onLoadMore={handleLoadMore}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ const Nav = ({
|
|||
activeSegment,
|
||||
link,
|
||||
curNav,
|
||||
navs,
|
||||
navigationItems,
|
||||
createText,
|
||||
onCreate,
|
||||
onLoadmore,
|
||||
onLoadMore,
|
||||
isApp,
|
||||
}: INavProps) => {
|
||||
const setAppDetail = useAppStore(state => state.setAppDetail)
|
||||
|
|
@ -80,10 +80,10 @@ const Nav = ({
|
|||
<NavSelector
|
||||
isApp={isApp}
|
||||
curNav={curNav}
|
||||
navs={navs}
|
||||
navigationItems={navigationItems}
|
||||
createText={createText}
|
||||
onCreate={onCreate}
|
||||
onLoadmore={onLoadmore}
|
||||
onLoadMore={onLoadMore}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -24,31 +24,31 @@ export type NavItem = {
|
|||
link: string
|
||||
icon_type: AppIconType | null
|
||||
icon: string
|
||||
icon_background: string
|
||||
icon_background: string | null
|
||||
icon_url: string | null
|
||||
mode?: string
|
||||
}
|
||||
export type INavSelectorProps = {
|
||||
navs: NavItem[]
|
||||
navigationItems: NavItem[]
|
||||
curNav?: Omit<NavItem, 'link'>
|
||||
createText: string
|
||||
isApp?: boolean
|
||||
onCreate: (state: string) => void
|
||||
onLoadmore?: () => void
|
||||
onLoadMore?: () => void
|
||||
}
|
||||
|
||||
const NavSelector = ({ curNav, navs, createText, isApp, onCreate, onLoadmore }: INavSelectorProps) => {
|
||||
const NavSelector = ({ curNav, navigationItems, createText, isApp, onCreate, onLoadMore }: INavSelectorProps) => {
|
||||
const { t } = useTranslation()
|
||||
const router = useRouter()
|
||||
const { isCurrentWorkspaceEditor } = useAppContext()
|
||||
const setAppDetail = useAppStore(state => state.setAppDetail)
|
||||
|
||||
const handleScroll = useCallback(debounce((e) => {
|
||||
if (typeof onLoadmore === 'function') {
|
||||
if (typeof onLoadMore === 'function') {
|
||||
const { clientHeight, scrollHeight, scrollTop } = e.target
|
||||
|
||||
if (clientHeight + scrollTop > scrollHeight - 50)
|
||||
onLoadmore()
|
||||
onLoadMore()
|
||||
}
|
||||
}, 50), [])
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ const NavSelector = ({ curNav, navs, createText, isApp, onCreate, onLoadmore }:
|
|||
>
|
||||
<div className="overflow-auto px-1 py-1" style={{ maxHeight: '50vh' }} onScroll={handleScroll}>
|
||||
{
|
||||
navs.map(nav => (
|
||||
navigationItems.map(nav => (
|
||||
<MenuItem key={nav.id}>
|
||||
<div className='flex w-full cursor-pointer items-center truncate rounded-lg px-3 py-[6px] text-[14px] font-normal text-gray-700 hover:bg-gray-100' onClick={() => {
|
||||
if (curNav?.id === nav.id)
|
||||
|
|
|
|||
Loading…
Reference in New Issue