import IconFont from '@/components/icon-font'; import SimpleOverlay from '@/components/simple-overlay'; import { SearchOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Empty, Spin } from 'antd'; import _ from 'lodash'; import React, { useMemo } from 'react'; import 'simplebar-react/dist/simplebar.min.css'; import styled from 'styled-components'; import { modelSourceMap } from '../config'; import '../style/search-result.less'; import FileSkeleton from './file-skeleton'; 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; isEvaluating?: boolean; } const ItemFileWrapper = styled.div` display: flex; flex-direction: column; justify-content: center; width: 100%; gap: 24px; `; const SpinWrapper = styled.div` position: absolute; top: 0; left: 0; width: 100%; height: 100%; bottom: 0; display: flex; justify-content: center; `; const SearchResult: React.FC = (props) => { const { resultList, onSelect, isEvaluating, 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 = useMemo(() => { 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' })} /> ); }, [networkError, source, intl]); return (
{resultList.length ? ( {resultList.map((item, index) => (
handleSelect(e, item)} onKeyDown={(e) => handleOnEnter(e, item)} >
))}
) : props.loading ? ( {_.times(10, (index: number) => { return ( ); })} ) : ( renderEmpty )}
); }; export default SearchResult;