From 9ac66d08ef82d2f25ba2fdaa743ef772306af75f Mon Sep 17 00:00:00 2001 From: robo <30987265+Robonau@users.noreply.github.com> Date: Sat, 2 Apr 2022 01:34:10 +0100 Subject: [PATCH] items per row setting (#165) * items per row setting self explanatory * make it better for user --- src/components/MangaCard.tsx | 7 ++- src/components/MangaGrid.tsx | 61 ++++++++++++++++++-------- src/screens/Settings.tsx | 85 ++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 20 deletions(-) diff --git a/src/components/MangaCard.tsx b/src/components/MangaCard.tsx index 995055dd..2beffa55 100644 --- a/src/components/MangaCard.tsx +++ b/src/components/MangaCard.tsx @@ -71,6 +71,7 @@ const truncateText = (str: string, maxLength: number) => { interface IProps { manga: IMangaCard gridLayout: number | undefined + dimensions: number } const MangaCard = React.forwardRef((props: IProps, ref) => { const { @@ -79,15 +80,19 @@ const MangaCard = React.forwardRef((props: IProps, ref) id, title, thumbnailUrl, downloadCount, unreadCount: unread, inLibrary, }, gridLayout, + dimensions, } = props; const { options: { showUnreadBadge, showDownloadBadge } } = useLibraryOptionsContext(); const [serverAddress] = useLocalStorage('serverBaseURL', ''); const [useCache] = useLocalStorage('useCache', true); + const [ItemWidth] = useLocalStorage('ItemWidth', 300); if (gridLayout !== 2) { + const colomns = Math.round(dimensions / ItemWidth); return ( - + // @ts-ignore gridsize type isnt allowed to be a decimal but it works fine + (null); + + const TestDimensions = () => { + setDimensions(gridRef.current ? gridRef.current.offsetWidth : 0); + }; + + useLayoutEffect(TestDimensions, []); + + let movementTimer: NodeJS.Timeout; + + window.addEventListener('resize', () => { + clearInterval(movementTimer); + movementTimer = setTimeout(TestDimensions, 100); + }); + if (mangas.length === 0) { if (isLoading) { mapped = ( @@ -79,6 +98,7 @@ export default function MangaGrid(props: IMangaGridProps) { manga={it} ref={lastManga} gridLayout={gridLayout} + dimensions={dimensions} /> ); } @@ -87,30 +107,33 @@ export default function MangaGrid(props: IMangaGridProps) { key={it.id} manga={it} gridLayout={gridLayout} + dimensions={dimensions} /> ); }); } return ( - - {mapped} - +
+ + {mapped} + +
); } diff --git a/src/screens/Settings.tsx b/src/screens/Settings.tsx index 2de7cfb6..a59dc871 100644 --- a/src/screens/Settings.tsx +++ b/src/screens/Settings.tsx @@ -27,6 +27,9 @@ import DialogContent from '@mui/material/DialogContent'; import DialogContentText from '@mui/material/DialogContentText'; import TextField from '@mui/material/TextField'; import FavoriteIcon from '@mui/icons-material/Favorite'; +import Slider from '@mui/material/Slider'; +import { DialogTitle, ListItemButton } from '@mui/material'; +import ViewModuleIcon from '@mui/icons-material/ViewModule'; import NavbarContext from '../components/context/NavbarContext'; import DarkTheme from '../components/context/DarkTheme'; import useLocalStorage from '../util/useLocalStorage'; @@ -43,6 +46,10 @@ export default function Settings() { const [dialogOpen, setDialogOpen] = useState(false); const [dialogValue, setDialogValue] = useState(serverAddress); + const [dialogOpenItemWidth, setDialogOpenItemWidth] = useState(false); + const [ItemWidth, setItemWidth] = useLocalStorage('ItemWidth', 6); + const [DialogItemWidth, setDialogItemWidth] = useState(ItemWidth); + const handleDialogOpen = () => { setDialogValue(serverAddress); setDialogOpen(true); @@ -57,6 +64,29 @@ export default function Settings() { setServerAddress(dialogValue); }; + const handleDialogOpenItemWidth = () => { + setDialogItemWidth(ItemWidth); + setDialogOpenItemWidth(true); + }; + + const handleDialogCancelItemWidth = () => { + setDialogOpenItemWidth(false); + }; + + const handleDialogSubmitItemWidth = () => { + setDialogOpenItemWidth(false); + setItemWidth(DialogItemWidth); + }; + + const handleDialogResetItemWidth = () => { + setDialogOpenItemWidth(false); + setItemWidth(300); + }; + + const handleChange = (event: Event, newValue: number | number[]) => { + setDialogItemWidth(newValue as number); + }; + return ( <> @@ -85,6 +115,18 @@ export default function Settings() { /> + + + + + { + handleDialogOpenItemWidth(); + }} + /> + @@ -168,6 +210,49 @@ export default function Settings() { + + + + Manga Item width + + + setDialogItemWidth(parseInt(e.target.value, 10))} + /> + + + + + + + + ); }