From d699955345e253d2b2c2d837e76509a39b3bef00 Mon Sep 17 00:00:00 2001 From: robo <30987265+Robonau@users.noreply.github.com> Date: Sat, 5 Mar 2022 23:33:34 +0000 Subject: [PATCH] add comfortable grid and all the stuff needed to make it easy to add more --- src/components/MangaCard.tsx | 109 +++++++++++------- src/components/MangaGrid.tsx | 6 +- .../context/LibraryOptionsContext.tsx | 3 +- src/components/library/LibraryMangaGrid.tsx | 3 + src/components/library/LibraryOptions.tsx | 33 ++++++ .../library/LibraryOptionsProvider.tsx | 2 +- src/typings.d.ts | 1 + 7 files changed, 112 insertions(+), 45 deletions(-) diff --git a/src/components/MangaCard.tsx b/src/components/MangaCard.tsx index 5006ac3149..fa41ffebcf 100644 --- a/src/components/MangaCard.tsx +++ b/src/components/MangaCard.tsx @@ -13,7 +13,7 @@ import { Link } from 'react-router-dom'; import { Grid } from '@mui/material'; import useLocalStorage from 'util/useLocalStorage'; import SpinnerImage from 'components/util/SpinnerImage'; -import { styled } from '@mui/system'; +import { Box, styled } from '@mui/system'; import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext'; const BottomGradient = styled('div')({ @@ -70,12 +70,14 @@ const truncateText = (str: string, maxLength: number) => { interface IProps { manga: IMangaCard + gridLayout: number | undefined } const MangaCard = React.forwardRef((props: IProps, ref) => { const { manga: { id, title, thumbnailUrl, downloadCount, unreadCount: unread, }, + gridLayout, } = props; const { options: { showUnreadBadge, showDownloadBadge } } = useLibraryOptionsContext(); @@ -84,60 +86,83 @@ const MangaCard = React.forwardRef((props: IProps, ref) return ( - - + - + - - { showUnreadBadge && unread! > 0 && ( - - {unread} - - )} - { showDownloadBadge && downloadCount! > 0 && ( - + { showUnreadBadge && unread! > 0 && ( + + {unread} + + )} + { showDownloadBadge && downloadCount! > 0 && ( + + {downloadCount} + + )} + + - {downloadCount} - + spinnerStyle={{ + display: 'grid', + placeItems: 'center', + }} + /> + {(gridLayout === 1) ? (<>) : ( + <> + + + )} - - + ) : ( + + {truncateText(title, 61)} + + )} + + + {(gridLayout === 1) ? ( + - - - - + > {truncateText(title, 61)} - - + ) : (<>)} + ); diff --git a/src/components/MangaGrid.tsx b/src/components/MangaGrid.tsx index d0ac770c8f..7917980984 100644 --- a/src/components/MangaGrid.tsx +++ b/src/components/MangaGrid.tsx @@ -19,11 +19,13 @@ export interface IMangaGridProps{ hasNextPage: boolean lastPageNum: number setLastPageNum: (lastPageNum: number) => void + gridLayout?: number | undefined } export default function MangaGrid(props: IMangaGridProps) { const { - mangas, isLoading, message, messageExtra, hasNextPage, lastPageNum, setLastPageNum, + mangas, isLoading, message, messageExtra, + hasNextPage, lastPageNum, setLastPageNum, gridLayout, } = props; let mapped; const lastManga = useRef(null); @@ -61,6 +63,7 @@ export default function MangaGrid(props: IMangaGridProps) { key={it.id} manga={it} ref={lastManga} + gridLayout={gridLayout} /> ); } @@ -68,6 +71,7 @@ export default function MangaGrid(props: IMangaGridProps) { ); }); diff --git a/src/components/context/LibraryOptionsContext.tsx b/src/components/context/LibraryOptionsContext.tsx index 6c975fb208..b550b9112a 100644 --- a/src/components/context/LibraryOptionsContext.tsx +++ b/src/components/context/LibraryOptionsContext.tsx @@ -8,12 +8,13 @@ import React, { useContext } from 'react'; type ContextType = { + // display options options: LibraryDisplayOptions; setOptions: React.Dispatch>; }; const LibraryOptionsContext = React.createContext({ - options: { showDownloadBadge: false, showUnreadBadge: false }, + options: { showDownloadBadge: false, showUnreadBadge: false, gridLayout: 0 }, setOptions: () => {}, }); diff --git a/src/components/library/LibraryMangaGrid.tsx b/src/components/library/LibraryMangaGrid.tsx index 262753705d..bfc9abc1eb 100644 --- a/src/components/library/LibraryMangaGrid.tsx +++ b/src/components/library/LibraryMangaGrid.tsx @@ -9,6 +9,7 @@ import React from 'react'; import MangaGrid, { IMangaGridProps } from 'components/MangaGrid'; import useLibraryOptions from 'util/useLibraryOptions'; +import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext'; const FILTERED_OUT_MESSAGE = 'There are no Manga matching this filter'; @@ -79,6 +80,7 @@ export default function LibraryMangaGrid(props: IMangaGridProps) { mangas, isLoading, hasNextPage, lastPageNum, setLastPageNum, message, } = props; + const { options } = useLibraryOptionsContext(); const { active, query } = useLibraryOptions(); const filteredManga = filterManga(mangas); const sortedManga = sortManga(filteredManga); @@ -93,6 +95,7 @@ export default function LibraryMangaGrid(props: IMangaGridProps) { lastPageNum={lastPageNum} setLastPageNum={setLastPageNum} message={showFilteredOutMessage ? FILTERED_OUT_MESSAGE : message} + gridLayout={options.gridLayout} /> ); } diff --git a/src/components/library/LibraryOptions.tsx b/src/components/library/LibraryOptions.tsx index bca0fcce82..f88a610318 100644 --- a/src/components/library/LibraryOptions.tsx +++ b/src/components/library/LibraryOptions.tsx @@ -21,6 +21,7 @@ import { ListItemButton, ListItemIcon, ListItemText, + Radio, } from '@mui/material'; import useLibraryOptions from 'util/useLibraryOptions'; import ThreeStateCheckbox from 'components/util/ThreeStateCheckbox'; @@ -111,9 +112,41 @@ function dispalyTab(currentTab: number) { ) { setOptions((prev) => ({ ...prev, [e.target.name]: checked })); } + + function setGridContextOptions( + e: React.ChangeEvent, + checked: boolean, + ) { + if (checked) { + setOptions((prev) => ({ ...prev, gridLayout: parseInt(e.target.name, 10) })); + } + } + return ( + DISPLAY MODE + + )} + /> + + )} + /> + BADGES ('libraryOptions', - { showDownloadBadge: false, showUnreadBadge: false }); + { showDownloadBadge: false, showUnreadBadge: false, gridLayout: 0 }); return ( diff --git a/src/typings.d.ts b/src/typings.d.ts index 5a9cfaa565..7eea6a3b19 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -264,4 +264,5 @@ type ChapterOptionsReducerAction = interface LibraryDisplayOptions { showDownloadBadge: boolean showUnreadBadge: boolean + gridLayout: number }