import { useCallback } from 'react' import { Model } from '@janhq/core' import { Modal, ModalTrigger, ModalClose, ModalFooter, ModalContent, ModalHeader, Button, ModalTitle, Progress, } from '@janhq/uikit' import { useAtomValue } from 'jotai' import useDownloadModel from '@/hooks/useDownloadModel' import { modelDownloadStateAtom } from '@/hooks/useDownloadState' import { formatDownloadPercentage } from '@/utils/converter' import { getDownloadingModelAtom } from '@/helpers/atoms/Model.atom' type Props = { model: Model isFromList?: boolean } const ModalCancelDownload: React.FC = ({ model, isFromList }) => { const { abortModelDownload } = useDownloadModel() const downloadingModels = useAtomValue(getDownloadingModelAtom) const allDownloadStates = useAtomValue(modelDownloadStateAtom) const downloadState = allDownloadStates[model.id] const cancelText = `Cancel ${formatDownloadPercentage(downloadState.percent)}` const onAbortDownloadClick = useCallback(() => { if (downloadState?.modelId) { const model = downloadingModels.find( (model) => model.id === downloadState.modelId ) if (model) abortModelDownload(model) } }, [downloadState, downloadingModels, abortModelDownload]) return ( {isFromList ? ( ) : ( )} Cancel Download

Are you sure you want to cancel the download of  {downloadState?.modelId}?

) } export default ModalCancelDownload