import { useCallback } from 'react' import { Model } from '@janhq/core' 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 = { model: Model isFromList?: boolean } const ModalCancelDownload = ({ model, isFromList }: Props) => { const { abortModelDownload } = useDownloadModel() const removeDownloadState = useSetAtom(removeDownloadStateAtom) const allDownloadStates = useAtomValue(modelDownloadStateAtom) const downloadState = allDownloadStates[model.id] const cancelText = `Cancel ${formatDownloadPercentage(downloadState?.percent ?? 0)}` const onAbortDownloadClick = useCallback(() => { removeDownloadState(model.id) abortModelDownload(downloadState?.modelId ?? model.id) }, [downloadState, abortModelDownload, removeDownloadState, model]) return ( {cancelText} ) : ( ) } content={

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

} /> ) } export default ModalCancelDownload