From fe6757f308d6afcdbec8823d6bc500302f40c5cf Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 14 Sep 2024 03:01:07 +0200 Subject: [PATCH] Migrate to mui grid v2 --- src/components/MangaGrid.tsx | 24 +++++------- src/components/library/LibraryMangaGrid.tsx | 1 + src/components/source/BaseMangaGrid.tsx | 2 +- src/screens/SearchAll.tsx | 27 ++++++++------ src/screens/SourceMangas.tsx | 41 ++++++--------------- 5 files changed, 38 insertions(+), 57 deletions(-) diff --git a/src/components/MangaGrid.tsx b/src/components/MangaGrid.tsx index c7f711c0..0e642245 100644 --- a/src/components/MangaGrid.tsx +++ b/src/components/MangaGrid.tsx @@ -16,8 +16,8 @@ import React, { useRef, useState, } from 'react'; -import Grid, { GridTypeMap } from '@mui/material/Grid'; -import Box from '@mui/material/Box'; +import Grid, { Grid2TypeMap as GridTypeMap } from '@mui/material/Grid2'; +import Box, { BoxProps } from '@mui/material/Box'; import { GridItemProps, GridStateSnapshot, VirtuosoGrid } from 'react-virtuoso'; import { useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; @@ -35,7 +35,7 @@ import { useResizeObserver } from '@/util/useResizeObserver.tsx'; import { useNavBarContext } from '@/components/context/NavbarContext.tsx'; const GridContainer = React.forwardRef(({ children, ...props }, ref) => ( - + {children} )); @@ -51,7 +51,7 @@ const GridItemContainerWithDimension = ( // MUI GridProps and Virtuoso GridItemProps use different types for the "ref" prop which conflict with each other return ({ children, ...itemProps }: GridTypeMap['props'] & Omit, 'ref'>) => ( - + {children} ); @@ -109,10 +109,8 @@ const HorizontalGrid = forwardRef( ref={ref} container spacing={1} - style={{ - margin: 0, + sx={{ width: '100%', - padding: '5px', overflowX: 'auto', display: '-webkit-inline-box', flexWrap: 'nowrap', @@ -232,6 +230,7 @@ export interface IMangaGridProps loadMore: () => void; horizontal?: boolean | undefined; noFaces?: boolean | undefined; + gridWrapperProps?: Omit; } export const MangaGrid: React.FC = ({ @@ -250,6 +249,7 @@ export const MangaGrid: React.FC = ({ handleSelection, mode, retry, + gridWrapperProps, }) => { const { t } = useTranslation(); @@ -353,13 +353,7 @@ export const MangaGrid: React.FC = ({ } return ( -
+ {horizontal ? ( = ({ mode={mode} /> )} -
+ ); }; diff --git a/src/components/library/LibraryMangaGrid.tsx b/src/components/library/LibraryMangaGrid.tsx index 2f9f6480..b72bb25a 100644 --- a/src/components/library/LibraryMangaGrid.tsx +++ b/src/components/library/LibraryMangaGrid.tsx @@ -44,6 +44,7 @@ export const LibraryMangaGrid: React.FC = ({ return ( undefined} diff --git a/src/components/source/BaseMangaGrid.tsx b/src/components/source/BaseMangaGrid.tsx index fcc8a4ca..17d75c80 100644 --- a/src/components/source/BaseMangaGrid.tsx +++ b/src/components/source/BaseMangaGrid.tsx @@ -13,5 +13,5 @@ type TMangaBaseGrid = Omit & { mangas: TMangaBaseGrid[] }) { const { mangas } = props; - return ; + return ; } diff --git a/src/screens/SearchAll.tsx b/src/screens/SearchAll.tsx index 0ce6ba91..9e4bd348 100644 --- a/src/screens/SearchAll.tsx +++ b/src/screens/SearchAll.tsx @@ -13,6 +13,7 @@ import React, { useCallback, useContext, useEffect, useMemo, useState } from 're import { Link, useLocation } from 'react-router-dom'; import { StringParam, useQueryParam } from 'use-query-params'; import { useTranslation } from 'react-i18next'; +import Box from '@mui/material/Box'; import { requestManager } from '@/lib/requests/RequestManager.ts'; import { useLocalStorage } from '@/util/useStorage.tsx'; import { langSortCmp, sourceDefualtLangs, sourceForcedDefaultLangs } from '@/util/language'; @@ -144,7 +145,7 @@ const SourceSearchPreview = React.memo( return ( <> - + {displayName} {translateExtensionLanguage(lang)} @@ -167,6 +168,7 @@ const SourceSearchPreview = React.memo( /> ) : ( { } return ( - <> - {sourcesSortedByResult.map((source) => ( - + + {sourcesSortedByResult.map((source, index) => ( + + + ))} - + ); }; diff --git a/src/screens/SourceMangas.tsx b/src/screens/SourceMangas.tsx index e9c81a1e..e9904e6e 100644 --- a/src/screens/SourceMangas.tsx +++ b/src/screens/SourceMangas.tsx @@ -49,37 +49,20 @@ import { MangaIdInfo } from '@/lib/data/Mangas.ts'; const ContentTypeMenu = styled('div')(({ theme }) => ({ display: 'flex', - position: 'fixed', - top: '64px', + position: 'sticky', width: '100%', zIndex: 1, + padding: theme.spacing(1), + gap: theme.spacing(1), backgroundColor: theme.palette.background.default, - [theme.breakpoints.down('sm')]: { - top: '56px', // header height - }, })); -const ContentTypeButton = styled(Button)(() => ({ - marginTop: '13px', - marginBottom: '13px', - marginLeft: '13px', -})); +const ContentTypeButton = styled(Button)(() => ({})); -const StyledGridWrapper = styled(Box, { shouldForwardProp: (prop) => prop !== 'hasContent' })<{ hasContent: boolean }>( - ({ theme, hasContent }) => ({ - // 62.5px ContentTypeMenu height (- padding of grid + grid item) - marginTop: `calc(62.5px ${hasContent ? '- 8px' : ''})`, - // header height - ContentTypeMenu height - minHeight: 'calc(100vh - 64px - 62.5px)', - position: 'relative', - [theme.breakpoints.down('sm')]: { - // 62.5px ContentTypeMenu - 8px margin diff header height (56px) (- padding of grid item) - marginTop: `calc(62.5px - 8px ${hasContent ? '- 8px' : ''})`, - // header height (+ 8px margin) - footer height - ContentTypeMenu height - minHeight: 'calc(100vh - 64px - 64px - 62.5px)', - }, - }), -); +const StyledGridWrapper = styled(Box)(() => ({ + minHeight: '100%', + position: 'relative', +})); export enum SourceContentType { POPULAR, @@ -212,7 +195,7 @@ const useSourceManga = ( export function SourceMangas() { const { t } = useTranslation(); - const { setTitle, setAction } = useContext(NavBarContext); + const { setTitle, setAction, appBarHeight } = useContext(NavBarContext); const { sourceId } = useParams<{ sourceId: string }>(); @@ -226,7 +209,6 @@ export function SourceMangas() { }>().state ?? {}; const [isFirstRender, setIsFirstRender] = useState(true); - useEffect(() => { setIsFirstRender(false); }, []); @@ -444,8 +426,8 @@ export function SourceMangas() { }, [t, source]); return ( - - + + } @@ -473,6 +455,7 @@ export function SourceMangas() {