import { useCallback } from 'react' import { Modal, Button, Progress, ModalClose } from '@janhq/joi' import { useAtomValue, useSetAtom } from 'jotai' import useDownloadModel from '@/hooks/useDownloadModel' import { modelDownloadStateAtom, removeDownloadStateAtom, } from '@/hooks/useDownloadState' import { formatDownloadPercentage } from '@/utils/converter' type Props = { modelId: string isFromList?: boolean } const ModalCancelDownload = ({ modelId, isFromList }: Props) => { const { abortModelDownload } = useDownloadModel() const removeDownloadState = useSetAtom(removeDownloadStateAtom) const allDownloadStates = useAtomValue(modelDownloadStateAtom) const downloadState = allDownloadStates[modelId] const cancelText = `Cancel ${formatDownloadPercentage(downloadState?.percent ?? 0)}` const onAbortDownloadClick = useCallback(() => { removeDownloadState(modelId) abortModelDownload(downloadState?.modelId ?? modelId) }, [downloadState, abortModelDownload, removeDownloadState, modelId]) return ( {cancelText} ) : ( ) } content={

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

} /> ) } export default ModalCancelDownload