From 6b2245d730eececc6e462b1b771cd676a45e1eaa Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 25 Nov 2023 15:39:39 +0100 Subject: [PATCH] Move the last update timestamp to the body (#472) On small screens, the last update timestamp caused the pages title to get cut --- src/screens/Updates.tsx | 195 +++++++++++++++++++++------------------- 1 file changed, 104 insertions(+), 91 deletions(-) diff --git a/src/screens/Updates.tsx b/src/screens/Updates.tsx index b16638a7..8e0bea2f 100644 --- a/src/screens/Updates.tsx +++ b/src/screens/Updates.tsx @@ -13,7 +13,7 @@ import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import IconButton from '@mui/material/IconButton'; import Typography from '@mui/material/Typography'; -import React, { useCallback, useContext, useEffect, useMemo } from 'react'; +import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { t as translate } from 'i18next'; @@ -27,12 +27,14 @@ import { TChapter } from '@/typings.ts'; import { NavBarContext } from '@/components/context/NavbarContext.tsx'; import { UpdateChecker } from '@/components/library/UpdateChecker.tsx'; -const StyledGroupedVirtuoso = styled(GroupedVirtuoso)(({ theme }) => ({ +const StyledGroupedVirtuoso = styled(GroupedVirtuoso, { shouldForwardProp: (prop) => prop !== 'heightToSubtract' })<{ + heightToSubtract: number; +}>(({ theme, heightToSubtract }) => ({ // 64px header - height: 'calc(100vh - 64px)', + height: `calc(100vh - 64px - ${heightToSubtract}px)`, [theme.breakpoints.down('sm')]: { // 64px header (margin); 64px menu (margin); - height: 'calc(100vh - 64px - 64px)', + height: `calc(100vh - 64px - 64px - ${heightToSubtract}px)`, }, })); @@ -118,6 +120,12 @@ export const Updates: React.FC = () => { const { data: downloaderData } = requestManager.useDownloadSubscription(); const queue = (downloaderData?.downloadChanged.queue as DownloadType[]) ?? []; + const lastUpdateTimestampCompRef = useRef(null); + const [lastUpdateTimestampCompHeight, setLastUpdateTimestampCompHeight] = useState(0); + useLayoutEffect(() => { + setLastUpdateTimestampCompHeight(lastUpdateTimestampCompRef.current?.clientHeight ?? 0); + }, [lastUpdateTimestampCompRef.current]); + const { data: lastUpdateTimestampData } = requestManager.useGetLastGlobalUpdateTimestamp({ /** * The {@link UpdateChecker} is responsible for updating the timestamp @@ -129,16 +137,7 @@ export const Updates: React.FC = () => { useEffect(() => { setTitle(t('updates.title')); - setAction( - <> - - {t('library.settings.global_update.label.last_update', { - date: lastUpdateTimestamp ? new Date(+lastUpdateTimestamp).toLocaleString() : '-', - })} - - - , - ); + setAction(); }, [t, lastUpdateTimestamp]); const downloadForChapter = (chapter: TChapter) => { @@ -166,85 +165,99 @@ export const Updates: React.FC = () => { } return ( - (isLoading ? : null), - }} - overscan={window.innerHeight * 0.5} - endReached={loadMore} - groupCounts={groupCounts} - groupContent={(index) => ( - - {groupedUpdates[index][0]} - - )} - itemContent={(index) => { - const chapter = updateEntries[index]; - const { manga } = chapter; - const download = downloadForChapter(chapter); + <> + ({ [theme.breakpoints.up('sm')]: { paddingTop: '6px' } }), + }} + > + {t('library.settings.global_update.label.last_update', { + date: lastUpdateTimestamp ? new Date(+lastUpdateTimestamp).toLocaleString() : '-', + })} + + (isLoading ? : null), + }} + overscan={window.innerHeight * 0.5} + endReached={loadMore} + groupCounts={groupCounts} + groupContent={(index) => ( + + {groupedUpdates[index][0]} + + )} + itemContent={(index) => { + const chapter = updateEntries[index]; + const { manga } = chapter; + const download = downloadForChapter(chapter); - return ( - - - - + + - - - - - {manga.title} - - - {chapter.name} - - - - {download && } - {download == null && !chapter.isDownloaded && ( - - { - e.stopPropagation(); - e.preventDefault(); - downloadChapter(chapter); + + + - - - - )} - - - - - ); - }} - /> + src={requestManager.getValidImgUrlFor(manga.thumbnailUrl ?? '')} + /> + + + {manga.title} + + + {chapter.name} + + + + {download && } + {download == null && !chapter.isDownloaded && ( + + { + e.stopPropagation(); + e.preventDefault(); + downloadChapter(chapter); + }} + size="large" + > + + + + )} + + + + + ); + }} + /> + ); };