import { Fragment } from 'react' import { Progress, Modal, Button } from '@janhq/joi' import { useAtomValue, useSetAtom } from 'jotai' import useDownloadModel from '@/hooks/useDownloadModel' import { modelDownloadStateAtom, removeDownloadStateAtom, } from '@/hooks/useDownloadState' import { formatDownloadPercentage } from '@/utils/converter' export default function DownloadingState() { const downloadStates = useAtomValue(modelDownloadStateAtom) const removeDownloadState = useSetAtom(removeDownloadStateAtom) 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 && (
{totalPercentage}%
} content={
{Object.values(downloadStates).map((item, i) => (

{item?.modelId}

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