'use client' import type { FC } from 'react' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' import CheckboxWithLabel from './base/checkbox-with-label' import CrawledResultItem from './crawled-result-item' import cn from '@/utils/classnames' import type { CrawlResultItem } from '@/models/datasets' const I18N_PREFIX = 'datasetCreation.stepOne.website' type Props = { className?: string list: CrawlResultItem[] checkedList: CrawlResultItem[] onSelectedChange: (selected: CrawlResultItem[]) => void onPreview: (payload: CrawlResultItem) => void usedTime: number } const CrawledResult: FC = ({ className = '', list, checkedList, onSelectedChange, onPreview, usedTime, }) => { const { t } = useTranslation() const isCheckAll = checkedList.length === list.length const handleCheckedAll = useCallback(() => { if (!isCheckAll) onSelectedChange(list) else onSelectedChange([]) }, [isCheckAll, list, onSelectedChange]) const handleItemCheckChange = useCallback((item: CrawlResultItem) => { return (checked: boolean) => { if (checked) onSelectedChange([...checkedList, item]) else onSelectedChange(checkedList.filter(checkedItem => checkedItem.source_url !== item.source_url)) } }, [checkedList, onSelectedChange]) const [previewIndex, setPreviewIndex] = React.useState(-1) const handlePreview = useCallback((index: number) => { return () => { setPreviewIndex(index) onPreview(list[index]) } }, [list, onPreview]) return (
{t(`${I18N_PREFIX}.scrapTimeInfo`, { total: list.length, time: usedTime.toFixed(1), })}
{list.map((item, index) => ( checkedItem.source_url === item.source_url)} onCheckChange={handleItemCheckChange(item)} /> ))}
) } export default React.memo(CrawledResult)