import IconFont from '@/components/icon-font'; import { SearchOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Col, Empty, Row, Spin } from 'antd'; import React from 'react'; import SimpleBar from 'simplebar-react'; import 'simplebar-react/dist/simplebar.min.css'; import { modelSourceMap } from '../config'; import '../style/search-result.less'; import HFModelItem from './hf-model-item'; interface SearchResultProps { resultList: any[]; onSelect?: (item: any) => void; current?: string; source?: string; style?: React.CSSProperties; loading?: boolean; networkError?: boolean; } const SearchResult: React.FC = (props) => { const { resultList, onSelect, source, networkError } = props; const intl = useIntl(); const handleSelect = (e: any, item: any) => { e.stopPropagation(); onSelect?.(item); }; const handleOnEnter = (e: any, item: any) => { e.stopPropagation(); if (e.key === 'Enter') { onSelect?.(item); } }; const renderEmpty = () => { if (networkError) { return ( } description={ source === modelSourceMap.huggingface_value ? (
{intl.formatMessage({ id: 'models.search.networkerror' })} {intl.formatMessage({ id: 'models.search.hfvisit' })}
) : null } /> ); } return ( } description={intl.formatMessage({ id: 'models.search.noresult' })} /> ); }; return (
{resultList.length ? ( {resultList.map((item, index) => (
handleSelect(e, item)} onKeyDown={(e) => handleOnEnter(e, item)} >
))}
) : ( !props.loading && renderEmpty() )}
); }; export default React.memo(SearchResult);