fix: optimize callback functions in StepOne component

pull/22182/head
twwu 11 months ago
parent bcd6cfacbd
commit 1d64ff4625

@ -1,5 +1,5 @@
'use client' 'use client'
import React, { useMemo, useState } from 'react' import React, { useCallback, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { RiArrowRightLine, RiFolder6Line } from '@remixicon/react' import { RiArrowRightLine, RiFolder6Line } from '@remixicon/react'
import FilePreview from '../file-preview' import FilePreview from '../file-preview'
@ -95,24 +95,29 @@ const StepOne = ({
const modalShowHandle = () => setShowModal(true) const modalShowHandle = () => setShowModal(true)
const modalCloseHandle = () => setShowModal(false) const modalCloseHandle = () => setShowModal(false)
const updateCurrentFile = (file: File) => { const updateCurrentFile = useCallback((file: File) => {
setCurrentFile(file) setCurrentFile(file)
} }, [])
const hideFilePreview = () => {
const hideFilePreview = useCallback(() => {
setCurrentFile(undefined) setCurrentFile(undefined)
} }, [])
const updateCurrentPage = (page: NotionPage) => { const updateCurrentPage = useCallback((page: NotionPage) => {
setCurrentNotionPage(page) setCurrentNotionPage(page)
} }, [])
const hideNotionPagePreview = () => { const hideNotionPagePreview = useCallback(() => {
setCurrentNotionPage(undefined) setCurrentNotionPage(undefined)
} }, [])
const updateWebsite = useCallback((website: CrawlResultItem) => {
setCurrentWebsite(website)
}, [])
const hideWebsitePreview = () => { const hideWebsitePreview = useCallback(() => {
setCurrentWebsite(undefined) setCurrentWebsite(undefined)
} }, [])
const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type) const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type)
const isInCreatePage = shouldShowDataSourceTypeList const isInCreatePage = shouldShowDataSourceTypeList
@ -158,8 +163,8 @@ const StepOne = ({
if (dataSourceTypeDisable) if (dataSourceTypeDisable)
return return
changeType(DataSourceType.FILE) changeType(DataSourceType.FILE)
hideFilePreview()
hideNotionPagePreview() hideNotionPagePreview()
hideWebsitePreview()
}} }}
> >
<span className={cn(s.datasetIcon)} /> <span className={cn(s.datasetIcon)} />
@ -182,7 +187,7 @@ const StepOne = ({
return return
changeType(DataSourceType.NOTION) changeType(DataSourceType.NOTION)
hideFilePreview() hideFilePreview()
hideNotionPagePreview() hideWebsitePreview()
}} }}
> >
<span className={cn(s.datasetIcon, s.notion)} /> <span className={cn(s.datasetIcon, s.notion)} />
@ -201,7 +206,13 @@ const StepOne = ({
dataSourceType === DataSourceType.WEB && s.active, dataSourceType === DataSourceType.WEB && s.active,
dataSourceTypeDisable && dataSourceType !== DataSourceType.WEB && s.disabled, dataSourceTypeDisable && dataSourceType !== DataSourceType.WEB && s.disabled,
)} )}
onClick={() => changeType(DataSourceType.WEB)} onClick={() => {
if (dataSourceTypeDisable)
return
changeType(DataSourceType.WEB)
hideFilePreview()
hideNotionPagePreview()
}}
> >
<span className={cn(s.datasetIcon, s.web)} /> <span className={cn(s.datasetIcon, s.web)} />
<span <span
@ -276,7 +287,7 @@ const StepOne = ({
<> <>
<div className={cn('mb-8 w-[640px]', !shouldShowDataSourceTypeList && 'mt-12')}> <div className={cn('mb-8 w-[640px]', !shouldShowDataSourceTypeList && 'mt-12')}>
<Website <Website
onPreview={setCurrentWebsite} onPreview={updateWebsite}
checkedCrawlResult={websitePages} checkedCrawlResult={websitePages}
onCheckedCrawlResultChange={updateWebsitePages} onCheckedCrawlResultChange={updateWebsitePages}
onCrawlProviderChange={onWebsiteCrawlProviderChange} onCrawlProviderChange={onWebsiteCrawlProviderChange}

Loading…
Cancel
Save