Optionally trigger update for specific category
This commit is contained in:
@@ -459,6 +459,12 @@
|
||||
}
|
||||
},
|
||||
"library": {
|
||||
"action": {
|
||||
"label": {
|
||||
"update_category": "Update category",
|
||||
"update_library": "Update library"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"label": {
|
||||
"add_to_library": "Could not add manga to library!",
|
||||
|
||||
@@ -11,12 +11,16 @@ import IconButton from '@mui/material/IconButton';
|
||||
import RefreshIcon from '@mui/icons-material/Refresh';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
import PopupState, { bindMenu, bindTrigger } from 'material-ui-popup-state';
|
||||
import Menu from '@mui/material/Menu';
|
||||
import MenuItem from '@mui/material/MenuItem';
|
||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||
import { makeToast } from '@/components/util/Toast';
|
||||
import { UpdaterSubscription } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { Progress } from '@/components/util/Progress';
|
||||
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
||||
import { dateTimeFormatter } from '@/util/date.ts';
|
||||
import { TCategory } from '@/typings.ts';
|
||||
|
||||
const calcProgress = (status: UpdaterSubscription['updateStatusChanged'] | undefined) => {
|
||||
if (!status) {
|
||||
@@ -33,7 +37,13 @@ const calcProgress = (status: UpdaterSubscription['updateStatusChanged'] | undef
|
||||
|
||||
let lastRunningState = false;
|
||||
|
||||
export function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate?: () => void }) {
|
||||
export function UpdateChecker({
|
||||
categoryId,
|
||||
handleFinishedUpdate,
|
||||
}: {
|
||||
categoryId?: TCategory['id'];
|
||||
handleFinishedUpdate?: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data: lastUpdateTimestampData, refetch: reFetchLastTimestamp } =
|
||||
@@ -69,10 +79,10 @@ export function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate?:
|
||||
reFetchLastTimestamp().catch(defaultPromiseErrorHandler('UpdateChecker::reFetchLastTimestamp'));
|
||||
}, [status?.isRunning]);
|
||||
|
||||
const onClick = async () => {
|
||||
const onClick = async (category?: TCategory['id']) => {
|
||||
try {
|
||||
lastRunningState = true;
|
||||
await requestManager.startGlobalUpdate().response;
|
||||
await requestManager.startGlobalUpdate(category !== undefined ? [category] : undefined).response;
|
||||
reFetchLastTimestamp().catch(defaultPromiseErrorHandler('UpdateChecker::reFetchLastTimestamp'));
|
||||
} catch (e) {
|
||||
lastRunningState = false;
|
||||
@@ -86,9 +96,36 @@ export function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate?:
|
||||
date: lastUpdateTimestamp ? dateTimeFormatter.format(+lastUpdateTimestamp) : '-',
|
||||
})}
|
||||
>
|
||||
<IconButton onClick={onClick} disabled={loading}>
|
||||
{loading ? <Progress progress={progress} /> : <RefreshIcon />}
|
||||
</IconButton>
|
||||
<PopupState variant="popover" popupId="library-update-checker-menu">
|
||||
{(popupState) => (
|
||||
<>
|
||||
<IconButton
|
||||
{...(categoryId !== undefined ? bindTrigger(popupState) : { onClick: () => onClick() })}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? <Progress progress={progress} /> : <RefreshIcon />}
|
||||
</IconButton>
|
||||
<Menu {...bindMenu(popupState)}>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
popupState.close();
|
||||
onClick();
|
||||
}}
|
||||
>
|
||||
{t('library.action.label.update_library')}
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
popupState.close();
|
||||
onClick(categoryId);
|
||||
}}
|
||||
>
|
||||
{t('library.action.label.update_category')}
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</>
|
||||
)}
|
||||
</PopupState>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2455,7 +2455,7 @@ export class RequestManager {
|
||||
): AbortableApolloMutationResponse<UpdateLibraryMangasMutation>;
|
||||
|
||||
public startGlobalUpdate(
|
||||
categories: number[],
|
||||
categories?: number[],
|
||||
options?: MutationOptions<UpdateCategoryMangasMutation, UpdateCategoryMangasMutationVariables>,
|
||||
): AbortableApolloMutationResponse<UpdateCategoryMangasMutation>;
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ export function Library() {
|
||||
<>
|
||||
<AppbarSearch />
|
||||
<LibraryToolbarMenu />
|
||||
<UpdateChecker />
|
||||
<UpdateChecker categoryId={activeTab?.id} />
|
||||
</>
|
||||
)}
|
||||
<SelectableCollectionSelectMode
|
||||
@@ -185,6 +185,7 @@ export function Library() {
|
||||
areAllItemsSelected,
|
||||
selectedItemIds.length,
|
||||
mangas.length,
|
||||
activeTab,
|
||||
]);
|
||||
|
||||
const handleTabChange = (newTab: number) => {
|
||||
|
||||
Reference in New Issue
Block a user