Created a GridLayout enum and updated all locations to use it. (#208)
So, that we can more easily refactor the code later
This commit is contained in:
@@ -14,7 +14,7 @@ import { Avatar, CardContent, Grid } from '@mui/material';
|
|||||||
import useLocalStorage from 'util/useLocalStorage';
|
import useLocalStorage from 'util/useLocalStorage';
|
||||||
import SpinnerImage from 'components/util/SpinnerImage';
|
import SpinnerImage from 'components/util/SpinnerImage';
|
||||||
import { Box, styled } from '@mui/system';
|
import { Box, styled } from '@mui/system';
|
||||||
import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
import { GridLayout, useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
||||||
import { BACK } from 'util/useBackTo';
|
import { BACK } from 'util/useBackTo';
|
||||||
|
|
||||||
const BottomGradient = styled('div')({
|
const BottomGradient = styled('div')({
|
||||||
@@ -66,7 +66,7 @@ const truncateText = (str: string, maxLength: number) => {
|
|||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
manga: IMangaCard
|
manga: IMangaCard
|
||||||
gridLayout: number | undefined
|
gridLayout?: GridLayout
|
||||||
dimensions: number
|
dimensions: number
|
||||||
inLibraryIndicator?: boolean
|
inLibraryIndicator?: boolean
|
||||||
}
|
}
|
||||||
@@ -88,11 +88,11 @@ const MangaCard = React.forwardRef<HTMLDivElement, IProps>((props: IProps, ref)
|
|||||||
|
|
||||||
const mangaLinkTo = { pathname: `/manga/${id}/`, state: { backLink: BACK } };
|
const mangaLinkTo = { pathname: `/manga/${id}/`, state: { backLink: BACK } };
|
||||||
|
|
||||||
if (gridLayout !== 2) {
|
if (gridLayout !== GridLayout.List) {
|
||||||
const cols = Math.ceil(dimensions / ItemWidth);
|
const cols = Math.ceil(dimensions / ItemWidth);
|
||||||
return (
|
return (
|
||||||
<Grid item columns={cols} xs={1}>
|
<Grid item columns={cols} xs={1}>
|
||||||
<Link to={mangaLinkTo} style={(gridLayout === 1) ? { textDecoration: 'none' } : {}}>
|
<Link to={mangaLinkTo} style={(gridLayout === GridLayout.Comfortable) ? { textDecoration: 'none' } : {}}>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@@ -164,13 +164,13 @@ const MangaCard = React.forwardRef<HTMLDivElement, IProps>((props: IProps, ref)
|
|||||||
placeItems: 'center',
|
placeItems: 'center',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{(gridLayout === 1) ? (<></>) : (
|
{(gridLayout === GridLayout.Comfortable) ? (<></>) : (
|
||||||
<>
|
<>
|
||||||
<BottomGradient />
|
<BottomGradient />
|
||||||
<BottomGradientDoubledDown />
|
<BottomGradientDoubledDown />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{(gridLayout === 1) ? (
|
{(gridLayout === GridLayout.Comfortable) ? (
|
||||||
<></>
|
<></>
|
||||||
) : (
|
) : (
|
||||||
<MangaTitle
|
<MangaTitle
|
||||||
@@ -184,7 +184,7 @@ const MangaCard = React.forwardRef<HTMLDivElement, IProps>((props: IProps, ref)
|
|||||||
)}
|
)}
|
||||||
</CardActionArea>
|
</CardActionArea>
|
||||||
</Card>
|
</Card>
|
||||||
{(gridLayout === 1) ? (
|
{(gridLayout === GridLayout.Comfortable) ? (
|
||||||
<MangaTitle
|
<MangaTitle
|
||||||
sx={{
|
sx={{
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import LoadingPlaceholder from 'components/util/LoadingPlaceholder';
|
|||||||
import { Typography } from '@mui/material';
|
import { Typography } from '@mui/material';
|
||||||
import { Box } from '@mui/system';
|
import { Box } from '@mui/system';
|
||||||
import MangaCard from './MangaCard';
|
import MangaCard from './MangaCard';
|
||||||
|
import { GridLayout } from './context/LibraryOptionsContext';
|
||||||
|
|
||||||
export interface IMangaGridProps{
|
export interface IMangaGridProps{
|
||||||
mangas: IMangaCard[]
|
mangas: IMangaCard[]
|
||||||
@@ -23,7 +24,7 @@ export interface IMangaGridProps{
|
|||||||
hasNextPage: boolean
|
hasNextPage: boolean
|
||||||
lastPageNum: number
|
lastPageNum: number
|
||||||
setLastPageNum: (lastPageNum: number) => void
|
setLastPageNum: (lastPageNum: number) => void
|
||||||
gridLayout?: number | undefined
|
gridLayout?: GridLayout
|
||||||
horisontal?: boolean | undefined
|
horisontal?: boolean | undefined
|
||||||
noFaces?: boolean | undefined
|
noFaces?: boolean | undefined
|
||||||
inLibraryIndicator?: boolean
|
inLibraryIndicator?: boolean
|
||||||
|
|||||||
@@ -12,11 +12,17 @@ type ContextType = {
|
|||||||
setOptions: React.Dispatch<React.SetStateAction<LibraryOptions>>;
|
setOptions: React.Dispatch<React.SetStateAction<LibraryOptions>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export enum GridLayout {
|
||||||
|
Compact = 0,
|
||||||
|
Comfortable = 1,
|
||||||
|
List = 2,
|
||||||
|
}
|
||||||
|
|
||||||
export const DefaultLibraryOptions: LibraryOptions = {
|
export const DefaultLibraryOptions: LibraryOptions = {
|
||||||
showDownloadBadge: false,
|
showDownloadBadge: false,
|
||||||
showUnreadBadge: false,
|
showUnreadBadge: false,
|
||||||
gridLayout: 0,
|
gridLayout: GridLayout.Compact,
|
||||||
SourcegridLayout: 0,
|
SourcegridLayout: GridLayout.Compact,
|
||||||
|
|
||||||
downloaded: undefined,
|
downloaded: undefined,
|
||||||
sortDesc: undefined,
|
sortDesc: undefined,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import CheckboxInput from 'components/atoms/CheckboxInput';
|
|||||||
import RadioInput from 'components/atoms/RadioInput';
|
import RadioInput from 'components/atoms/RadioInput';
|
||||||
import SortRadioInput from 'components/atoms/SortRadioInput';
|
import SortRadioInput from 'components/atoms/SortRadioInput';
|
||||||
import ThreeStateCheckboxInput from 'components/atoms/ThreeStateCheckboxInput';
|
import ThreeStateCheckboxInput from 'components/atoms/ThreeStateCheckboxInput';
|
||||||
import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
import { GridLayout, useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
||||||
import OptionsTabs from 'components/molecules/OptionsTabs';
|
import OptionsTabs from 'components/molecules/OptionsTabs';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
@@ -78,9 +78,9 @@ const LibraryOptionsPanel: React.FC<IProps> = ({ open, onClose }) => {
|
|||||||
onChange={(e) => handleFilterChange('gridLayout', Number(e.target.value))}
|
onChange={(e) => handleFilterChange('gridLayout', Number(e.target.value))}
|
||||||
value={gridLayout}
|
value={gridLayout}
|
||||||
>
|
>
|
||||||
<RadioInput label="Compact grid" value={0} checked={gridLayout == null || gridLayout === 0} />
|
<RadioInput label="Compact grid" value={GridLayout.Compact} checked={gridLayout == null || gridLayout === GridLayout.Compact} />
|
||||||
<RadioInput label="Comfortable grid" value={1} checked={gridLayout === 1} />
|
<RadioInput label="Comfortable grid" value={GridLayout.Comfortable} checked={gridLayout === GridLayout.Comfortable} />
|
||||||
<RadioInput label="List" value={2} checked={gridLayout === 2} />
|
<RadioInput label="List" value={GridLayout.List} checked={gridLayout === GridLayout.List} />
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
|
||||||
<FormLabel sx={{ mt: 2 }}>Badges</FormLabel>
|
<FormLabel sx={{ mt: 2 }}>Badges</FormLabel>
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ViewModuleIcon from '@mui/icons-material/ViewModule';
|
import ViewModuleIcon from '@mui/icons-material/ViewModule';
|
||||||
import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
import { GridLayout, useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
||||||
|
|
||||||
|
// TODO: clean up this to use a FormControl, and remove dependency on name o radio button
|
||||||
export default function SourceGridLayout() {
|
export default function SourceGridLayout() {
|
||||||
const { options, setOptions } = useLibraryOptionsContext();
|
const { options: { SourcegridLayout }, setOptions } = useLibraryOptionsContext();
|
||||||
|
|
||||||
const [anchorEl, setAnchorEl] = React.useState(null);
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
||||||
const open = Boolean(anchorEl);
|
const open = Boolean(anchorEl);
|
||||||
@@ -55,11 +56,14 @@ export default function SourceGridLayout() {
|
|||||||
<MenuItem onClick={handleClose}>
|
<MenuItem onClick={handleClose}>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
label="Compact grid"
|
label="Compact grid"
|
||||||
|
value={GridLayout.Compact}
|
||||||
control={(
|
control={(
|
||||||
<Radio
|
<Radio
|
||||||
name="0"
|
name={GridLayout.Compact.toString()}
|
||||||
// eslint-disable-next-line max-len
|
checked={
|
||||||
checked={options.SourcegridLayout === 0 || options.SourcegridLayout === undefined}
|
SourcegridLayout === GridLayout.Compact
|
||||||
|
|| SourcegridLayout === undefined
|
||||||
|
}
|
||||||
onChange={setGridContextOptions}
|
onChange={setGridContextOptions}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -70,8 +74,8 @@ export default function SourceGridLayout() {
|
|||||||
label="Comfortable grid"
|
label="Comfortable grid"
|
||||||
control={(
|
control={(
|
||||||
<Radio
|
<Radio
|
||||||
name="1"
|
name={GridLayout.Comfortable.toString()}
|
||||||
checked={options.SourcegridLayout === 1}
|
checked={SourcegridLayout === GridLayout.Comfortable}
|
||||||
onChange={setGridContextOptions}
|
onChange={setGridContextOptions}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -82,15 +86,14 @@ export default function SourceGridLayout() {
|
|||||||
label="List"
|
label="List"
|
||||||
control={(
|
control={(
|
||||||
<Radio
|
<Radio
|
||||||
name="2"
|
name={GridLayout.List.toString()}
|
||||||
checked={options.SourcegridLayout === 2}
|
checked={SourcegridLayout === GridLayout.List}
|
||||||
onChange={setGridContextOptions}
|
onChange={setGridContextOptions}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/typings.d.ts
vendored
10
src/typings.d.ts
vendored
@@ -280,12 +280,18 @@ type ChapterOptionsReducerAction =
|
|||||||
|
|
||||||
type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortID';
|
type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortID';
|
||||||
|
|
||||||
|
enum GridLayout {
|
||||||
|
Compact = 0,
|
||||||
|
Comfortable = 1,
|
||||||
|
List = 2,
|
||||||
|
}
|
||||||
|
|
||||||
interface LibraryOptions {
|
interface LibraryOptions {
|
||||||
// display options
|
// display options
|
||||||
showDownloadBadge: boolean
|
showDownloadBadge: boolean
|
||||||
showUnreadBadge: boolean
|
showUnreadBadge: boolean
|
||||||
gridLayout: number
|
gridLayout: GridLayout
|
||||||
SourcegridLayout:number
|
SourcegridLayout: GridLayout
|
||||||
|
|
||||||
// filter options
|
// filter options
|
||||||
downloaded: NullAndUndefined<boolean>
|
downloaded: NullAndUndefined<boolean>
|
||||||
|
|||||||
Reference in New Issue
Block a user