2022-11-26 13:51:56 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-06-04 21:08:39 +02:00
|
|
|
import { CircularProgress, Box } from '@mui/material';
|
2022-11-26 13:51:56 +01:00
|
|
|
import Typography from '@mui/material/Typography';
|
|
|
|
|
import React from 'react';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { IDownloadChapter, TranslationKey } from 'typings';
|
2022-11-26 13:51:56 +01:00
|
|
|
|
|
|
|
|
interface DownloadStateIndicatorProps {
|
2023-02-06 10:06:33 +01:00
|
|
|
download: IDownloadChapter;
|
2022-11-26 13:51:56 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 13:59:32 +01:00
|
|
|
const DOWNLOAD_STATE_TO_TRANSLATION_KEY_MAP: { [state in IDownloadChapter['state']]: TranslationKey } = {
|
|
|
|
|
Downloading: 'download.state.label.downloading',
|
|
|
|
|
Error: 'download.state.label.error',
|
|
|
|
|
Finished: 'download.state.label.finished',
|
|
|
|
|
Queued: 'download.state.label.queued',
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
const DownloadStateIndicator: React.FC<DownloadStateIndicatorProps> = ({ download }) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
return (
|
2022-11-26 13:51:56 +01:00
|
|
|
<Box
|
|
|
|
|
sx={{
|
2023-03-23 13:59:32 +01:00
|
|
|
position: 'relative',
|
|
|
|
|
display: 'inline-flex',
|
|
|
|
|
width: '50px',
|
2022-11-26 13:51:56 +01:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-03-23 13:59:32 +01:00
|
|
|
{download.progress !== 0 && <CircularProgress variant="determinate" value={download.progress * 100} />}
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
bottom: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant="caption" component="div" color="text.secondary">
|
2023-06-04 21:40:04 +02:00
|
|
|
<>
|
|
|
|
|
{download.progress !== 0 && `${Math.round(download.progress * 100)}%`}
|
|
|
|
|
{download.progress === 0 && t(DOWNLOAD_STATE_TO_TRANSLATION_KEY_MAP[download.state])}
|
|
|
|
|
</>
|
2023-03-23 13:59:32 +01:00
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
2022-11-26 13:51:56 +01:00
|
|
|
</Box>
|
2023-03-23 13:59:32 +01:00
|
|
|
);
|
|
|
|
|
};
|
2022-11-26 13:51:56 +01:00
|
|
|
|
|
|
|
|
export default DownloadStateIndicator;
|