NamH 52d56a8ae1
refactor: move file to jan root (#598)
* feat: move necessary files to jan root

Signed-off-by: James <james@jan.ai>

* chore: check model dir

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: Louis <louis@jan.ai>
2023-11-16 12:09:09 +07:00

86 lines
2.2 KiB
TypeScript

import { useMemo } from 'react'
import { ModelVersion } from '@janhq/core/lib/types'
import {
Modal,
ModalTrigger,
ModalClose,
ModalFooter,
ModalContent,
ModalHeader,
Button,
ModalTitle,
} from '@janhq/uikit'
import { atom, useAtomValue } from 'jotai'
import { useDownloadState } from '@/hooks/useDownloadState'
import useGetPerformanceTag from '@/hooks/useGetPerformanceTag'
import { formatDownloadPercentage } from '@/utils/converter'
type Props = {
suitableModel: ModelVersion
isFromList?: boolean
}
export default function ModalCancelDownload({
suitableModel,
isFromList,
}: Props) {
const { modelDownloadStateAtom } = useDownloadState()
useGetPerformanceTag()
const downloadAtom = useMemo(
() => atom((get) => get(modelDownloadStateAtom)[suitableModel.id]),
// eslint-disable-next-line react-hooks/exhaustive-deps
[suitableModel.id]
)
const downloadState = useAtomValue(downloadAtom)
return (
<Modal>
<ModalTrigger asChild>
{isFromList ? (
<Button themes="outline" size="sm">
Cancel ({formatDownloadPercentage(downloadState.percent)})
</Button>
) : (
<Button>
Cancel ({formatDownloadPercentage(downloadState.percent)})
</Button>
)}
</ModalTrigger>
<ModalContent>
<ModalHeader>
<ModalTitle>Cancel Download</ModalTitle>
</ModalHeader>
<p>
Are you sure you want to cancel the download of&nbsp;
{downloadState?.fileName}?
</p>
<ModalFooter>
<div className="flex gap-x-2">
<ModalClose asChild>
<Button themes="ghost">No</Button>
</ModalClose>
<ModalClose asChild>
<Button
themes="danger"
onClick={() => {
if (downloadState?.fileName)
window.coreAPI?.abortDownload(
`models/${downloadState?.fileName}`
)
}}
>
Yes
</Button>
</ModalClose>
</div>
</ModalFooter>
</ModalContent>
</Modal>
)
}