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