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