/* eslint-disable react-hooks/exhaustive-deps */ import React, { useMemo } from 'react' import { Model } from '@janhq/core' import { Badge, Button } 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: Model isRecommended: boolean } const ModelVersionItem: React.FC = ({ model }) => { const { downloadModel } = useDownloadModel() const { downloadedModels } = useGetDownloadedModels() const { setMainViewState } = useMainViewState() const isDownloaded = downloadedModels.find( (downloadedModel) => downloadedModel.id === model.id ) != null const { modelDownloadStateAtom, downloadStates } = useDownloadState() const downloadAtom = useMemo( () => atom((get) => get(modelDownloadStateAtom)[model.id ?? '']), [model.id] ) const downloadState = useAtomValue(downloadAtom) const onDownloadClick = () => { downloadModel(model) } let downloadButton = ( ) if (isDownloaded) { downloadButton = ( ) } if (downloadState != null && downloadStates.length > 0) { downloadButton = } return (
{model.name}
{`${toGigabytes( model.metadata.maxRamRequired )} RAM required`} {toGigabytes(model.metadata.size)}
{downloadButton}
) } export default ModelVersionItem