/* eslint-disable react-hooks/exhaustive-deps */ import React, { useMemo } from 'react' import { ModelCatalog, ModelVersion } from '@janhq/core/lib/types' import { Button } from '@janhq/uikit' import { Badge } from '@janhq/uikit' import { atom, useAtomValue } from 'jotai' import ModalCancelDownload from '@/containers/ModalCancelDownload' import { MainViewState } from '@/constants/screens' import useDownloadModel from '@/hooks/useDownloadModel' import { useDownloadState } from '@/hooks/useDownloadState' import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels' import { useMainViewState } from '@/hooks/useMainViewState' import { toGigabytes } from '@/utils/converter' type Props = { model: ModelCatalog modelVersion: ModelVersion isRecommended: boolean } const ModelVersionItem: React.FC = ({ model, modelVersion }) => { const { downloadModel } = useDownloadModel() const { downloadedModels } = useGetDownloadedModels() const { setMainViewState } = useMainViewState() const isDownloaded = downloadedModels.find((model) => model._id === modelVersion._id) != null const { modelDownloadStateAtom, downloadStates } = useDownloadState() const downloadAtom = useMemo( () => atom((get) => get(modelDownloadStateAtom)[modelVersion._id ?? '']), [modelVersion._id] ) const downloadState = useAtomValue(downloadAtom) const onDownloadClick = () => { downloadModel(model, modelVersion) } let downloadButton = ( ) if (isDownloaded) { downloadButton = ( ) } if (downloadState != null && downloadStates.length > 0) { downloadButton = ( ) } const { maxRamRequired, usecase } = modelVersion return (
{modelVersion.name}
{usecase} {`${toGigabytes( maxRamRequired )} RAM required`} {toGigabytes(modelVersion.size)}
{downloadButton}
) } export default ModelVersionItem