From cdf922945764eb26d7cdba5007f5fb8d1d44bbbd Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 19 Nov 2023 22:43:29 +0100 Subject: [PATCH] Feature/global update show last update time (#468) * Show last global update timestamp * Add update button to "Updates" screen --- src/components/library/UpdateChecker.tsx | 10 +++++++++- src/i18n/locale/en.json | 4 ++++ src/lib/requests/RequestManager.ts | 18 +++++++++++++++++- src/screens/Updates.tsx | 18 ++++++++++++++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/components/library/UpdateChecker.tsx b/src/components/library/UpdateChecker.tsx index c7a002bf..5e33bf09 100644 --- a/src/components/library/UpdateChecker.tsx +++ b/src/components/library/UpdateChecker.tsx @@ -32,6 +32,9 @@ const calcProgress = (status: UpdaterSubscription['updateStatusChanged'] | undef export function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate: () => void }) { const { t } = useTranslation(); + const { data: lastUpdateTimestampData, refetch: refetchlastTimestamp } = + requestManager.useGetLastGlobalUpdateTimestamp(); + const lastUpdateTimestamp = lastUpdateTimestampData?.lastUpdateTimestamp.timestamp; const { data: updaterData } = requestManager.useUpdaterSubscription(); const status = updaterData?.updateStatusChanged; @@ -48,6 +51,7 @@ export function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate: const isUpdateFinished = progress === 100; if (isUpdateFinished) { + refetchlastTimestamp(); handleFinishedUpdate(); } @@ -60,7 +64,11 @@ export function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate: }; return ( - + {loading ? : } diff --git a/src/i18n/locale/en.json b/src/i18n/locale/en.json index 2ba11468..731fc5c8 100644 --- a/src/i18n/locale/en.json +++ b/src/i18n/locale/en.json @@ -382,6 +382,10 @@ }, "title": "Skip updating entries" }, + "label": { + "last_update": "Last update: {{date}}", + "last_update_tooltip": "$t(library.settings.global_update.title) ($t(library.settings.global_update.label.last_update, lowercase))" + }, "metadata": { "label": { "description": "Check for new cover and details when updating library", diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts index 2d028aca..08a55023 100644 --- a/src/lib/requests/RequestManager.ts +++ b/src/lib/requests/RequestManager.ts @@ -76,6 +76,8 @@ import { GetExtensionsQueryVariables, GetGlobalMetadatasQuery, GetGlobalMetadatasQueryVariables, + GetLastUpdateTimestampQuery, + GetLastUpdateTimestampQueryVariables, GetMangaChaptersFetchMutation, GetMangaChaptersFetchMutationVariables, GetMangaFetchMutation, @@ -200,7 +202,7 @@ import { UPDATE_CATEGORY_MANGAS, UPDATE_LIBRARY_MANGAS, } from '@/lib/graphql/mutations/UpdaterMutation.ts'; -import { GET_UPDATE_STATUS } from '@/lib/graphql/queries/UpdaterQuery.ts'; +import { GET_LAST_UPDATE_TIMESTAMP, GET_UPDATE_STATUS } from '@/lib/graphql/queries/UpdaterQuery.ts'; import { CustomCache } from '@/lib/requests/CustomCache.ts'; import { RESTORE_BACKUP } from '@/lib/graphql/mutations/BackupMutation.ts'; import { GET_RESTORE_STATUS, VALIDATE_BACKUP } from '@/lib/graphql/queries/BackupQuery.ts'; @@ -1918,6 +1920,20 @@ export class RequestManager { ): AbortableApolloUseMutationResponse { return this.doRequest(GQLMethod.USE_MUTATION, DOWNLOAD_AHEAD, undefined, options); } + + public useGetLastGlobalUpdateTimestamp( + options?: QueryHookOptions, + ): AbortableApolloUseQueryResponse { + return this.doRequest( + GQLMethod.USE_QUERY, + GET_LAST_UPDATE_TIMESTAMP, + {}, + { + fetchPolicy: 'network-only', + ...options, + }, + ); + } } export const requestManager = new RequestManager(); diff --git a/src/screens/Updates.tsx b/src/screens/Updates.tsx index bd6c9c8a..12b8029e 100644 --- a/src/screens/Updates.tsx +++ b/src/screens/Updates.tsx @@ -25,6 +25,7 @@ import { DownloadStateIndicator } from '@/components/molecules/DownloadStateIndi import { DownloadType } from '@/lib/graphql/generated/graphql.ts'; import { TChapter } from '@/typings.ts'; import { NavBarContext } from '@/components/context/NavbarContext.tsx'; +import { UpdateChecker } from '@/components/library/UpdateChecker.tsx'; const StyledGroupedVirtuoso = styled(GroupedVirtuoso)(({ theme }) => ({ // 64px header @@ -117,11 +118,24 @@ export const Updates: React.FC = () => { const { data: downloaderData } = requestManager.useDownloadSubscription(); const queue = (downloaderData?.downloadChanged.queue as DownloadType[]) ?? []; + const { data: lastUpdateTimestampData, refetch: refetchlastTimestamp } = + requestManager.useGetLastGlobalUpdateTimestamp(); + const lastUpdateTimestamp = lastUpdateTimestampData?.lastUpdateTimestamp.timestamp; + useEffect(() => { setTitle(t('updates.title')); - setAction(null); - }, [t]); + setAction( + <> + + {t('library.settings.global_update.label.last_update', { + date: lastUpdateTimestamp ? new Date(+lastUpdateTimestamp).toLocaleString() : '-', + })} + + refetchlastTimestamp()} /> + , + ); + }, [t, lastUpdateTimestamp]); const downloadForChapter = (chapter: TChapter) => { const {