import { Fragment } from 'react' import { Progress, Modal, ModalContent, Button, ModalHeader, ModalTitle, ModalTrigger, } 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' export default function DownloadingState() { const downloadStates = useAtomValue(modelDownloadStateAtom) const downloadingModels = useAtomValue(getDownloadingModelAtom) const { abortModelDownload } = useDownloadModel() const totalCurrentProgress = Object.values(downloadStates) .map((a) => a.size.transferred + a.size.transferred) .reduce((partialSum, a) => partialSum + a, 0) const totalSize = Object.values(downloadStates) .map((a) => a.size.total + a.size.total) .reduce((partialSum, a) => partialSum + a, 0) const totalPercentage = totalSize !== 0 ? ((totalCurrentProgress / totalSize) * 100).toFixed(2) : 0 return ( {Object.values(downloadStates)?.length > 0 && (
Downloading model {Object.values(downloadStates).map((item, i) => (

{item?.modelId}

{formatDownloadPercentage(item?.percent)}
))}
)}
) }