Refresh library mangas after update
the gql updater subscription currently return stale data, thus, the mangas do net get updated in the cache
This commit is contained in:
@@ -45,7 +45,7 @@ const calcProgress = (status: UpdaterSubscription['updateStatusChanged'] | undef
|
|||||||
return Number.isNaN(progress) ? 0 : progress;
|
return Number.isNaN(progress) ? 0 : progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
function UpdateChecker() {
|
function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate: () => void }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { data: updaterData } = requestManager.useUpdaterSubscription();
|
const { data: updaterData } = requestManager.useUpdaterSubscription();
|
||||||
@@ -62,6 +62,11 @@ function UpdateChecker() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isUpdateFinished = progress === 100;
|
||||||
|
if (isUpdateFinished) {
|
||||||
|
handleFinishedUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
const onClick = async () => {
|
const onClick = async () => {
|
||||||
try {
|
try {
|
||||||
await requestManager.startGlobalUpdate().response;
|
await requestManager.startGlobalUpdate().response;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Chip, Tab, Tabs, styled, Box } from '@mui/material';
|
import { Chip, Tab, Tabs, styled, Box } from '@mui/material';
|
||||||
import React, { useContext, useEffect, useMemo } from 'react';
|
import React, { useCallback, useContext, useEffect, useMemo } from 'react';
|
||||||
import { useQueryParam, NumberParam } from 'use-query-params';
|
import { useQueryParam, NumberParam } from 'use-query-params';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import requestManager from '@/lib/requests/RequestManager.ts';
|
import requestManager from '@/lib/requests/RequestManager.ts';
|
||||||
@@ -66,6 +66,7 @@ export default function Library() {
|
|||||||
data: categoriesResponse,
|
data: categoriesResponse,
|
||||||
error: tabsError,
|
error: tabsError,
|
||||||
loading: areCategoriesLoading,
|
loading: areCategoriesLoading,
|
||||||
|
refetch,
|
||||||
} = requestManager.useGetCategories();
|
} = requestManager.useGetCategories();
|
||||||
const tabsData = categoriesResponse?.categories.nodes.filter(
|
const tabsData = categoriesResponse?.categories.nodes.filter(
|
||||||
(category) => category.id !== 0 || (category.id === 0 && category.mangas.totalCount),
|
(category) => category.id !== 0 || (category.id === 0 && category.mangas.totalCount),
|
||||||
@@ -86,6 +87,10 @@ export default function Library() {
|
|||||||
} = requestManager.useGetCategoryMangas(activeTab?.id, { skip: !activeTab, nextFetchPolicy: 'cache-only' });
|
} = requestManager.useGetCategoryMangas(activeTab?.id, { skip: !activeTab, nextFetchPolicy: 'cache-only' });
|
||||||
const mangas = categoryMangaResponse?.mangas.nodes ?? [];
|
const mangas = categoryMangaResponse?.mangas.nodes ?? [];
|
||||||
|
|
||||||
|
const handleFinishedUpdate = useCallback(() => {
|
||||||
|
refetch();
|
||||||
|
}, [refetch]);
|
||||||
|
|
||||||
const { setTitle, setAction } = useContext(NavbarContext);
|
const { setTitle, setAction } = useContext(NavbarContext);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const title = t('library.title');
|
const title = t('library.title');
|
||||||
@@ -100,7 +105,7 @@ export default function Library() {
|
|||||||
<>
|
<>
|
||||||
<AppbarSearch />
|
<AppbarSearch />
|
||||||
<LibraryToolbarMenu />
|
<LibraryToolbarMenu />
|
||||||
<UpdateChecker />
|
<UpdateChecker handleFinishedUpdate={handleFinishedUpdate} />
|
||||||
</>,
|
</>,
|
||||||
);
|
);
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user