Add option to stop global update
This commit is contained in:
@@ -461,6 +461,7 @@
|
|||||||
"library": {
|
"library": {
|
||||||
"action": {
|
"action": {
|
||||||
"label": {
|
"label": {
|
||||||
|
"stop_update": "Stop global update",
|
||||||
"update_category": "Update category",
|
"update_category": "Update category",
|
||||||
"update_library": "Update library"
|
"update_library": "Update library"
|
||||||
}
|
}
|
||||||
@@ -470,7 +471,8 @@
|
|||||||
"add_to_library": "Could not add manga to library!",
|
"add_to_library": "Could not add manga to library!",
|
||||||
"empty": "Your library is empty",
|
"empty": "Your library is empty",
|
||||||
"no_matches": "No manga matches this filter",
|
"no_matches": "No manga matches this filter",
|
||||||
"remove_from_library": "Could not remove manga from library!"
|
"remove_from_library": "Could not remove manga from library!",
|
||||||
|
"stop_global_update": "Could not stop global update"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"info": {
|
"info": {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useEffect, useMemo } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
import RefreshIcon from '@mui/icons-material/Refresh';
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@@ -14,6 +14,8 @@ import Tooltip from '@mui/material/Tooltip';
|
|||||||
import PopupState, { bindMenu, bindTrigger } from 'material-ui-popup-state';
|
import PopupState, { bindMenu, bindTrigger } from 'material-ui-popup-state';
|
||||||
import Menu from '@mui/material/Menu';
|
import Menu from '@mui/material/Menu';
|
||||||
import MenuItem from '@mui/material/MenuItem';
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
|
import ClearIcon from '@mui/icons-material/Clear';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||||
import { makeToast } from '@/components/util/Toast';
|
import { makeToast } from '@/components/util/Toast';
|
||||||
import { UpdaterSubscription } from '@/lib/graphql/generated/graphql.ts';
|
import { UpdaterSubscription } from '@/lib/graphql/generated/graphql.ts';
|
||||||
@@ -21,6 +23,7 @@ import { Progress } from '@/components/util/Progress';
|
|||||||
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
||||||
import { dateTimeFormatter } from '@/util/date.ts';
|
import { dateTimeFormatter } from '@/util/date.ts';
|
||||||
import { TCategory } from '@/typings.ts';
|
import { TCategory } from '@/typings.ts';
|
||||||
|
import { MediaQuery } from '@/lib/ui/MediaQuery.tsx';
|
||||||
|
|
||||||
const calcProgress = (status: UpdaterSubscription['updateStatusChanged'] | undefined) => {
|
const calcProgress = (status: UpdaterSubscription['updateStatusChanged'] | undefined) => {
|
||||||
if (!status) {
|
if (!status) {
|
||||||
@@ -45,6 +48,9 @@ export function UpdateChecker({
|
|||||||
handleFinishedUpdate?: () => void;
|
handleFinishedUpdate?: () => void;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const isTouchDevice = MediaQuery.useIsTouchDevice();
|
||||||
|
|
||||||
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
|
||||||
const { data: lastUpdateTimestampData, refetch: reFetchLastTimestamp } =
|
const { data: lastUpdateTimestampData, refetch: reFetchLastTimestamp } =
|
||||||
requestManager.useGetLastGlobalUpdateTimestamp();
|
requestManager.useGetLastGlobalUpdateTimestamp();
|
||||||
@@ -52,7 +58,7 @@ export function UpdateChecker({
|
|||||||
const { data: updaterData } = requestManager.useGetGlobalUpdateSummary();
|
const { data: updaterData } = requestManager.useGetGlobalUpdateSummary();
|
||||||
const status = updaterData?.updateStatus;
|
const status = updaterData?.updateStatus;
|
||||||
|
|
||||||
const loading = !!status?.isRunning;
|
const isRunning = !!status?.isRunning;
|
||||||
const progress = useMemo(
|
const progress = useMemo(
|
||||||
() => calcProgress(status),
|
() => calcProgress(status),
|
||||||
[
|
[
|
||||||
@@ -79,7 +85,7 @@ export function UpdateChecker({
|
|||||||
reFetchLastTimestamp().catch(defaultPromiseErrorHandler('UpdateChecker::reFetchLastTimestamp'));
|
reFetchLastTimestamp().catch(defaultPromiseErrorHandler('UpdateChecker::reFetchLastTimestamp'));
|
||||||
}, [status?.isRunning]);
|
}, [status?.isRunning]);
|
||||||
|
|
||||||
const onClick = async (category?: TCategory['id']) => {
|
const startUpdate = async (category?: TCategory['id']) => {
|
||||||
try {
|
try {
|
||||||
lastRunningState = true;
|
lastRunningState = true;
|
||||||
await requestManager.startGlobalUpdate(category !== undefined ? [category] : undefined).response;
|
await requestManager.startGlobalUpdate(category !== undefined ? [category] : undefined).response;
|
||||||
@@ -90,42 +96,75 @@ export function UpdateChecker({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const stopUpdate = async () => {
|
||||||
|
try {
|
||||||
|
await requestManager.resetGlobalUpdate();
|
||||||
|
} catch (e) {
|
||||||
|
makeToast(t('library.error.label.stop_global_update'), 'error');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onClick = async (category?: TCategory['id']) => {
|
||||||
|
if (isRunning) {
|
||||||
|
stopUpdate();
|
||||||
|
} else {
|
||||||
|
startUpdate(category);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<PopupState variant="popover" popupId="library-update-checker-menu">
|
||||||
title={t('library.settings.global_update.label.last_update_tooltip', {
|
{(popupState) => (
|
||||||
date: lastUpdateTimestamp ? dateTimeFormatter.format(+lastUpdateTimestamp) : '-',
|
<>
|
||||||
})}
|
<Tooltip
|
||||||
>
|
title={
|
||||||
<PopupState variant="popover" popupId="library-update-checker-menu">
|
isRunning
|
||||||
{(popupState) => (
|
? t('library.action.label.stop_update')
|
||||||
<>
|
: t('library.settings.global_update.label.last_update_tooltip', {
|
||||||
|
date: lastUpdateTimestamp ? dateTimeFormatter.format(+lastUpdateTimestamp) : '-',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
<IconButton
|
<IconButton
|
||||||
{...(categoryId !== undefined ? bindTrigger(popupState) : { onClick: () => onClick() })}
|
sx={{ position: 'relative' }}
|
||||||
disabled={loading}
|
{...(categoryId !== undefined && !isRunning
|
||||||
|
? bindTrigger(popupState)
|
||||||
|
: { onClick: () => onClick() })}
|
||||||
|
onMouseEnter={() => setIsHovered(true)}
|
||||||
|
onMouseLeave={() => setIsHovered(false)}
|
||||||
>
|
>
|
||||||
{loading ? <Progress progress={progress} /> : <RefreshIcon />}
|
{!isRunning ? (
|
||||||
|
<RefreshIcon />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ClearIcon sx={{ opacity: Number(isTouchDevice || isHovered) }} />
|
||||||
|
<Stack sx={{ position: 'absolute' }}>
|
||||||
|
<Progress progress={progress} showText={!isTouchDevice && !isHovered} />
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Menu {...bindMenu(popupState)}>
|
</Tooltip>
|
||||||
<MenuItem
|
<Menu {...bindMenu(popupState)}>
|
||||||
onClick={() => {
|
<MenuItem
|
||||||
popupState.close();
|
onClick={() => {
|
||||||
onClick();
|
popupState.close();
|
||||||
}}
|
onClick();
|
||||||
>
|
}}
|
||||||
{t('library.action.label.update_library')}
|
>
|
||||||
</MenuItem>
|
{t('library.action.label.update_library')}
|
||||||
<MenuItem
|
</MenuItem>
|
||||||
onClick={() => {
|
<MenuItem
|
||||||
popupState.close();
|
onClick={() => {
|
||||||
onClick(categoryId);
|
popupState.close();
|
||||||
}}
|
onClick(categoryId);
|
||||||
>
|
}}
|
||||||
{t('library.action.label.update_category')}
|
>
|
||||||
</MenuItem>
|
{t('library.action.label.update_category')}
|
||||||
</Menu>
|
</MenuItem>
|
||||||
</>
|
</Menu>
|
||||||
)}
|
</>
|
||||||
</PopupState>
|
)}
|
||||||
</Tooltip>
|
</PopupState>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import Box from '@mui/material/Box';
|
|||||||
import CircularProgress from '@mui/material/CircularProgress';
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
|
|
||||||
export const Progress = ({ progress }: { progress: number }) => (
|
export const Progress = ({ progress, showText = true }: { progress: number; showText?: boolean }) => (
|
||||||
<Box sx={{ display: 'grid', placeItems: 'center', position: 'relative' }}>
|
<Box sx={{ display: 'grid', placeItems: 'center', position: 'relative' }}>
|
||||||
<CircularProgress variant="determinate" value={progress} />
|
<CircularProgress variant="determinate" value={progress} />
|
||||||
<Box sx={{ position: 'absolute' }}>
|
{showText && (
|
||||||
<Typography fontSize="0.8rem">{`${Math.round(progress)}%`}</Typography>
|
<Box sx={{ position: 'absolute' }}>
|
||||||
</Box>
|
<Typography fontSize="0.8rem">{`${Math.round(progress)}%`}</Typography>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user