migrate ReaderNavbar to Mui 5 (#84)
* migrate ReaderNavbar to Mui 5 * cleanup, show loading text when loading.
This commit is contained in:
@@ -11,8 +11,7 @@ import KeyboardArrowLeftIcon from '@mui/icons-material/KeyboardArrowLeft';
|
||||
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
|
||||
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
||||
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
||||
import makeStyles from '@mui/styles/makeStyles';
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { useHistory, Link } from 'react-router-dom';
|
||||
import Slide from '@mui/material/Slide';
|
||||
@@ -27,19 +26,9 @@ import ListItemText from '@mui/material/ListItemText';
|
||||
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
|
||||
import Collapse from '@mui/material/Collapse';
|
||||
import Button from '@mui/material/Button';
|
||||
import NavBarContext from 'components/context/NavbarContext';
|
||||
import { styled } from '@mui/system';
|
||||
|
||||
const useStyles = (settings: IReaderSettings) => makeStyles((theme) => ({
|
||||
// main container and root div need to change classes...
|
||||
AppMainContainer: {
|
||||
display: 'none',
|
||||
},
|
||||
AppRootElment: {
|
||||
display: 'flex',
|
||||
},
|
||||
|
||||
root: {
|
||||
position: settings.staticNav ? 'sticky' : 'fixed',
|
||||
const Root = styled('div')(({ theme }) => ({
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '300px',
|
||||
@@ -68,10 +57,6 @@ const useStyles = (settings: IReaderSettings) => makeStyles((theme) => ({
|
||||
marginRight: '16px',
|
||||
},
|
||||
|
||||
'& button:nth-child(3)': {
|
||||
marginRight: '-12px',
|
||||
},
|
||||
|
||||
'& h1': {
|
||||
fontSize: '1.25rem',
|
||||
flexGrow: 1,
|
||||
@@ -83,18 +68,18 @@ const useStyles = (settings: IReaderSettings) => makeStyles((theme) => ({
|
||||
border: '0',
|
||||
backgroundColor: theme.palette.mode === 'dark' ? theme.palette.grey[800] : theme.palette.grey[100],
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
navigation: {
|
||||
const Navigation = styled('div')({
|
||||
margin: '0 16px',
|
||||
|
||||
'& > span:nth-child(1)': {
|
||||
textAlign: 'center',
|
||||
display: 'block',
|
||||
marginTop: '16px',
|
||||
},
|
||||
});
|
||||
|
||||
'& $navigationChapters': {
|
||||
const ChapterNavigation = styled('div')({
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr',
|
||||
gridTemplateAreas: '"prev next"',
|
||||
@@ -111,18 +96,9 @@ const useStyles = (settings: IReaderSettings) => makeStyles((theme) => ({
|
||||
textTransform: 'none',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
},
|
||||
navigationChapters: {}, // dummy rule
|
||||
|
||||
settingsCollapsseHeader: {
|
||||
'& span': {
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
},
|
||||
|
||||
openDrawerButton: {
|
||||
const OpenDrawerButton = styled(IconButton)(({ theme }) => ({
|
||||
position: 'fixed',
|
||||
top: 0 + 20,
|
||||
left: 10 + 20,
|
||||
@@ -130,11 +106,9 @@ const useStyles = (settings: IReaderSettings) => makeStyles((theme) => ({
|
||||
width: '40px',
|
||||
borderRadius: 5,
|
||||
backgroundColor: theme.palette.mode === 'dark' ? 'black' : 'white',
|
||||
|
||||
'&:hover': {
|
||||
backgroundColor: theme.palette.mode === 'dark' ? theme.palette.grey[900] : theme.palette.grey[100],
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
export const defaultReaderSettings = () => ({
|
||||
@@ -154,9 +128,6 @@ interface IProps {
|
||||
}
|
||||
|
||||
export default function ReaderNavBar(props: IProps) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { title } = useContext(NavBarContext);
|
||||
|
||||
const history = useHistory();
|
||||
|
||||
const {
|
||||
@@ -168,8 +139,6 @@ export default function ReaderNavBar(props: IProps) {
|
||||
const [prevScrollPos, setPrevScrollPos] = useState(0);
|
||||
const [settingsCollapseOpen, setSettingsCollapseOpen] = useState(true);
|
||||
|
||||
const classes = useStyles(settings)();
|
||||
|
||||
const setSettingValue = (key: string, value: any) => setSettings({ ...settings, [key]: value });
|
||||
|
||||
const handleScroll = () => {
|
||||
@@ -184,15 +153,16 @@ export default function ReaderNavBar(props: IProps) {
|
||||
useEffect(() => {
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
|
||||
const rootEl = document.querySelector('#root')!;
|
||||
const mainContainer = document.querySelector('#appMainContainer')!;
|
||||
const rootEl:HTMLDivElement = document.querySelector('#root')!;
|
||||
const mainContainer:HTMLDivElement = document.querySelector('#appMainContainer')!;
|
||||
|
||||
rootEl.classList.add(classes.AppRootElment);
|
||||
mainContainer.classList.add(classes.AppMainContainer);
|
||||
// main container and root div need to change styles...
|
||||
rootEl.style.display = 'flex';
|
||||
mainContainer.style.display = 'none';
|
||||
|
||||
return () => {
|
||||
rootEl.classList.remove(classes.AppRootElment);
|
||||
mainContainer.classList.remove(classes.AppMainContainer);
|
||||
rootEl.style.display = 'block';
|
||||
mainContainer.style.display = 'block';
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
};
|
||||
}, [handleScroll]);// handleScroll changes on every render
|
||||
@@ -207,8 +177,13 @@ export default function ReaderNavBar(props: IProps) {
|
||||
mountOnEnter
|
||||
unmountOnExit
|
||||
>
|
||||
<div className={classes.root}>
|
||||
<Root sx={{
|
||||
position: settings.staticNav ? 'sticky' : 'fixed',
|
||||
}}
|
||||
>
|
||||
<header>
|
||||
{!settings.staticNav
|
||||
&& (
|
||||
<IconButton
|
||||
edge="start"
|
||||
color="inherit"
|
||||
@@ -219,8 +194,8 @@ export default function ReaderNavBar(props: IProps) {
|
||||
>
|
||||
<KeyboardArrowLeftIcon />
|
||||
</IconButton>
|
||||
)}
|
||||
<Typography variant="h1">
|
||||
{/* {title} */}
|
||||
{chapter.name}
|
||||
</Typography>
|
||||
<IconButton
|
||||
@@ -230,11 +205,19 @@ export default function ReaderNavBar(props: IProps) {
|
||||
disableRipple
|
||||
onClick={() => history.goBack()}
|
||||
size="large"
|
||||
sx={{ mr: -1 }}
|
||||
>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
</header>
|
||||
<ListItem ContainerComponent="div" className={classes.settingsCollapsseHeader}>
|
||||
<ListItem
|
||||
ContainerComponent="div"
|
||||
sx={{
|
||||
'& span': {
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<ListItemText primary="Reader Settings" />
|
||||
<ListItemSecondaryAction>
|
||||
<IconButton
|
||||
@@ -286,64 +269,57 @@ export default function ReaderNavBar(props: IProps) {
|
||||
<ListItem>
|
||||
<ListItemText primary="Reader Type" />
|
||||
<Select
|
||||
variant="standard"
|
||||
value={settings.readerType}
|
||||
onChange={(e) => setSettingValue('readerType', e.target.value)}
|
||||
sx={{ p: 0 }}
|
||||
>
|
||||
<MenuItem value="SingleLTR">
|
||||
Single Page (LTR)
|
||||
|
||||
</MenuItem>
|
||||
<MenuItem value="SingleRTL">
|
||||
Single Page (RTL)
|
||||
|
||||
</MenuItem>
|
||||
{/* <MenuItem value="SingleVertical">
|
||||
Vertical(WIP)
|
||||
|
||||
</MenuItem> */}
|
||||
<MenuItem value="DoubleLTR">
|
||||
Double Page (LTR)
|
||||
|
||||
</MenuItem>
|
||||
<MenuItem value="DoubleRTL">
|
||||
Double Page (RTL)
|
||||
|
||||
</MenuItem>
|
||||
<MenuItem value="Webtoon">
|
||||
Webtoon
|
||||
|
||||
</MenuItem>
|
||||
<MenuItem value="ContinuesVertical">
|
||||
Continues Vertical
|
||||
|
||||
</MenuItem>
|
||||
<MenuItem value="ContinuesHorizontalLTR">
|
||||
Horizontal (LTR)
|
||||
|
||||
</MenuItem>
|
||||
<MenuItem value="ContinuesHorizontalRTL">
|
||||
Horizontal (RTL)
|
||||
|
||||
</MenuItem>
|
||||
</Select>
|
||||
</ListItem>
|
||||
</List>
|
||||
</Collapse>
|
||||
<hr />
|
||||
<div className={classes.navigation}>
|
||||
<Navigation>
|
||||
<span>
|
||||
{`Currently on page ${curPage + 1} of ${chapter.pageCount}`}
|
||||
</span>
|
||||
<div className={classes.navigationChapters}>
|
||||
<ChapterNavigation>
|
||||
{chapter.index > 1
|
||||
&& (
|
||||
<Link
|
||||
replace
|
||||
style={{ gridArea: 'prev' }}
|
||||
to={`/manga/${manga.id}/chapter/${chapter.index - 1}`}
|
||||
>
|
||||
<Button
|
||||
variant="outlined"
|
||||
sx={{ gridArea: 'prev' }}
|
||||
startIcon={<KeyboardArrowLeftIcon />}
|
||||
>
|
||||
Prev. Chapter
|
||||
@@ -365,14 +341,13 @@ export default function ReaderNavBar(props: IProps) {
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ChapterNavigation>
|
||||
</Navigation>
|
||||
</Root>
|
||||
</Slide>
|
||||
<Zoom in={!drawerOpen}>
|
||||
<Fade in={!hideOpenButton}>
|
||||
<IconButton
|
||||
className={classes.openDrawerButton}
|
||||
<OpenDrawerButton
|
||||
edge="start"
|
||||
color="inherit"
|
||||
aria-label="menu"
|
||||
@@ -382,7 +357,7 @@ export default function ReaderNavBar(props: IProps) {
|
||||
size="large"
|
||||
>
|
||||
<KeyboardArrowRightIcon />
|
||||
</IconButton>
|
||||
</OpenDrawerButton>
|
||||
</Fade>
|
||||
</Zoom>
|
||||
</>
|
||||
|
||||
@@ -58,7 +58,12 @@ const getReaderComponent = (readerType: ReaderType) => {
|
||||
};
|
||||
|
||||
const range = (n:number) => Array.from({ length: n }, (value, key) => key);
|
||||
const initialChapter = () => ({ pageCount: -1, index: -1, chapterCount: 0 });
|
||||
const initialChapter = () => ({
|
||||
pageCount: -1,
|
||||
index: -1,
|
||||
chapterCount: 0,
|
||||
name: 'Loading...',
|
||||
});
|
||||
|
||||
export default function Reader() {
|
||||
const [settings, setSettings] = useLocalStorage<IReaderSettings>('readerSettings', defaultReaderSettings);
|
||||
|
||||
Reference in New Issue
Block a user