import SimpleTag from '../SimpleTag' import PrimaryButton from '../PrimaryButton' import { formatDownloadPercentage, toGigabytes } from '@utils/converter' import SecondaryButton from '../SecondaryButton' import { useCallback, useEffect, useMemo } from 'react' import useGetPerformanceTag from '@hooks/useGetPerformanceTag' import useDownloadModel from '@hooks/useDownloadModel' import { useGetDownloadedModels } from '@hooks/useGetDownloadedModels' import { modelDownloadStateAtom } from '@helpers/atoms/DownloadState.atom' import { atom, useAtomValue, useSetAtom } from 'jotai' import { Button } from '@uikit' import { MainViewState, setMainViewStateAtom, } from '@helpers/atoms/MainView.atom' type Props = { suitableModel: ModelVersion exploreModel: Product } const ExploreModelItemHeader: React.FC = ({ suitableModel, exploreModel, }) => { const { downloadModel } = useDownloadModel() const { downloadedModels } = useGetDownloadedModels() const { performanceTag, title, getPerformanceForModel } = useGetPerformanceTag() const downloadAtom = useMemo( () => atom((get) => get(modelDownloadStateAtom)[suitableModel._id]), [suitableModel._id] ) const downloadState = useAtomValue(downloadAtom) const setMainViewState = useSetAtom(setMainViewStateAtom) useEffect(() => { getPerformanceForModel(suitableModel) // eslint-disable-next-line react-hooks/exhaustive-deps }, [suitableModel]) const onDownloadClick = useCallback(() => { downloadModel(exploreModel, suitableModel) // eslint-disable-next-line react-hooks/exhaustive-deps }, [exploreModel, suitableModel]) const isDownloaded = downloadedModels.find((model) => model._id === suitableModel._id) != null let downloadButton = ( ) if (isDownloaded) { downloadButton = ( ) } if (downloadState != null) { // downloading downloadButton = ( ) } return (
{exploreModel.name} {performanceTag && ( )}
{downloadButton}
) } export default ExploreModelItemHeader