From 3206944052819f125c0c668710683505b625a73b Mon Sep 17 00:00:00 2001
From: schroda <50052685+schroda@users.noreply.github.com>
Date: Wed, 26 Jun 2024 12:42:03 +0200
Subject: [PATCH] Optionally trigger update for specific category
---
public/locales/en.json | 6 +++
src/components/library/UpdateChecker.tsx | 49 +++++++++++++++++++++---
src/lib/requests/RequestManager.ts | 2 +-
src/screens/Library.tsx | 3 +-
4 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/public/locales/en.json b/public/locales/en.json
index 72f702e1..320113b0 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -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!",
diff --git a/src/components/library/UpdateChecker.tsx b/src/components/library/UpdateChecker.tsx
index e4c6c53f..258866f3 100644
--- a/src/components/library/UpdateChecker.tsx
+++ b/src/components/library/UpdateChecker.tsx
@@ -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) : '-',
})}
>
-
- {loading ? : }
-
+
+ {(popupState) => (
+ <>
+ onClick() })}
+ disabled={loading}
+ >
+ {loading ? : }
+
+
+ >
+ )}
+
);
}
diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts
index 4c896528..9e2a56f9 100644
--- a/src/lib/requests/RequestManager.ts
+++ b/src/lib/requests/RequestManager.ts
@@ -2455,7 +2455,7 @@ export class RequestManager {
): AbortableApolloMutationResponse;
public startGlobalUpdate(
- categories: number[],
+ categories?: number[],
options?: MutationOptions,
): AbortableApolloMutationResponse;
diff --git a/src/screens/Library.tsx b/src/screens/Library.tsx
index 94e6e77e..f64f9efc 100644
--- a/src/screens/Library.tsx
+++ b/src/screens/Library.tsx
@@ -149,7 +149,7 @@ export function Library() {
<>
-
+
>
)}
{