source layouts (#153)

This commit is contained in:
robo
2022-03-06 21:02:06 +00:00
committed by GitHub
parent 0a63d60880
commit 70b84b810f
6 changed files with 101 additions and 3 deletions

View File

@@ -14,7 +14,9 @@ type ContextType = {
}; };
const LibraryOptionsContext = React.createContext<ContextType>({ const LibraryOptionsContext = React.createContext<ContextType>({
options: { showDownloadBadge: false, showUnreadBadge: false, gridLayout: 0 }, options: {
showDownloadBadge: false, showUnreadBadge: false, gridLayout: 0, SourcegridLayout: 0,
},
setOptions: () => {}, setOptions: () => {},
}); });

View File

@@ -15,7 +15,9 @@ interface IProps {
export default function LibraryOptionsContextProvider({ children }: IProps) { export default function LibraryOptionsContextProvider({ children }: IProps) {
const [options, setOptions] = useLocalStorage<LibraryDisplayOptions>('libraryOptions', const [options, setOptions] = useLocalStorage<LibraryDisplayOptions>('libraryOptions',
{ showDownloadBadge: false, showUnreadBadge: false, gridLayout: 0 }); {
showDownloadBadge: false, showUnreadBadge: false, gridLayout: 0, SourcegridLayout: 0,
});
return ( return (
<LibraryOptionsContext.Provider value={{ options, setOptions }}> <LibraryOptionsContext.Provider value={{ options, setOptions }}>

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import {
IconButton, Menu, MenuItem, FormControlLabel, Radio,
} from '@mui/material';
import React from 'react';
import ViewModuleIcon from '@mui/icons-material/ViewModule';
import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
export default function SourceGridLayout() {
const { options, setOptions } = useLibraryOptionsContext();
const [anchorEl, setAnchorEl] = React.useState(null);
const open = Boolean(anchorEl);
const handleClick = (event: any) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
function setGridContextOptions(
e: React.ChangeEvent<HTMLInputElement>,
checked: boolean,
) {
if (checked) {
setOptions((prev: any) => ({ ...prev, SourcegridLayout: parseInt(e.target.name, 10) }));
}
}
return (
<>
<IconButton
onClick={handleClick}
size="small"
sx={{ ml: 2 }}
aria-controls={open ? 'account-menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
>
<ViewModuleIcon />
</IconButton>
<Menu
id="basic-menu"
anchorEl={anchorEl}
open={open}
onClose={handleClose}
MenuListProps={{ 'aria-labelledby': 'basic-button' }}
>
<MenuItem onClick={handleClose}>
<FormControlLabel
label="Compact grid"
control={(
<Radio
name="0"
// eslint-disable-next-line max-len
checked={options.SourcegridLayout === 0 || options.SourcegridLayout === undefined}
onChange={setGridContextOptions}
/>
)}
/>
</MenuItem>
<MenuItem onClick={handleClose}>
<FormControlLabel
label="Comfortable grid"
control={(
<Radio
name="1"
checked={options.SourcegridLayout === 1}
onChange={setGridContextOptions}
/>
)}
/>
</MenuItem>
</Menu>
</>
);
}

View File

@@ -17,7 +17,8 @@ function filterManga(mangas: IMangaCard[]): IMangaCard[] {
export default function SourceMangaGrid(props: IMangaGridProps) { export default function SourceMangaGrid(props: IMangaGridProps) {
const { const {
mangas, isLoading, hasNextPage, lastPageNum, setLastPageNum, message, messageExtra, mangas, isLoading, hasNextPage, lastPageNum,
setLastPageNum, message, messageExtra, gridLayout,
} = props; } = props;
const filteredManga = filterManga(mangas); const filteredManga = filterManga(mangas);
@@ -32,6 +33,7 @@ export default function SourceMangaGrid(props: IMangaGridProps) {
setLastPageNum={setLastPageNum} setLastPageNum={setLastPageNum}
message={showFilteredOutMessage ? FILTERED_OUT_MESSAGE : message} message={showFilteredOutMessage ? FILTERED_OUT_MESSAGE : message}
messageExtra={messageExtra} messageExtra={messageExtra}
gridLayout={gridLayout}
/> />
); );
} }

View File

@@ -15,6 +15,8 @@ import SettingsIcon from '@mui/icons-material/Settings';
import SourceOptions from 'components/source/SourceOptions'; import SourceOptions from 'components/source/SourceOptions';
import AppbarSearch from 'components/util/AppbarSearch'; import AppbarSearch from 'components/util/AppbarSearch';
import { useQueryParam, StringParam } from 'use-query-params'; import { useQueryParam, StringParam } from 'use-query-params';
import SourceGridLayout from 'components/source/GridLayouts';
import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
interface IPos { interface IPos {
position: number position: number
@@ -43,6 +45,8 @@ export default function SourceMangas(props: { popular: boolean }) {
const [Init, setInit] = useState<undefined | null>(); const [Init, setInit] = useState<undefined | null>();
const [Noreset, setNoreset] = useQueryParam('R'); const [Noreset, setNoreset] = useQueryParam('R');
const { options } = useLibraryOptionsContext();
function makeFilters() { function makeFilters() {
client.get(`/api/v1/source/${sourceId}/filters`) client.get(`/api/v1/source/${sourceId}/filters`)
.then((response) => response.data) .then((response) => response.data)
@@ -123,6 +127,7 @@ export default function SourceMangas(props: { popular: boolean }) {
useEffect(() => { useEffect(() => {
setAction( setAction(
<> <>
<SourceGridLayout />
<AppbarSearch /> <AppbarSearch />
{isConfigurable && ( {isConfigurable && (
<IconButton <IconButton
@@ -202,6 +207,7 @@ export default function SourceMangas(props: { popular: boolean }) {
message={message} message={message}
messageExtra={messageExtra} messageExtra={messageExtra}
isLoading={!fetched} isLoading={!fetched}
gridLayout={options.SourcegridLayout}
/> />
{Data !== undefined && ( {Data !== undefined && (
<SourceOptions <SourceOptions

1
src/typings.d.ts vendored
View File

@@ -265,4 +265,5 @@ interface LibraryDisplayOptions {
showDownloadBadge: boolean showDownloadBadge: boolean
showUnreadBadge: boolean showUnreadBadge: boolean
gridLayout: number gridLayout: number
SourcegridLayout:number
} }