migrate SpinnerImage to Mui 5 (#97)
* migrate Page to Mui 5 * migrate SpinnerImage to Mui 5 * match the style
This commit is contained in:
@@ -5,10 +5,10 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import makeStyles from '@mui/styles/makeStyles';
|
|
||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import SpinnerImage from 'components/util/SpinnerImage';
|
import SpinnerImage from 'components/util/SpinnerImage';
|
||||||
import useLocalStorage from 'util/useLocalStorage';
|
import useLocalStorage from 'util/useLocalStorage';
|
||||||
|
import Box from '@mui/system/Box';
|
||||||
|
|
||||||
function imageStyle(settings: IReaderSettings): any {
|
function imageStyle(settings: IReaderSettings): any {
|
||||||
const [dimensions, setDimensions] = React.useState({
|
const [dimensions, setDimensions] = React.useState({
|
||||||
@@ -53,22 +53,6 @@ function imageStyle(settings: IReaderSettings): any {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = (settings: IReaderSettings) => makeStyles({
|
|
||||||
loading: {
|
|
||||||
margin: '100px auto',
|
|
||||||
height: '100vh',
|
|
||||||
width: '100vw',
|
|
||||||
},
|
|
||||||
loadingImage: {
|
|
||||||
height: '100vh',
|
|
||||||
width: '70vw',
|
|
||||||
padding: '50px calc(50% - 20px)',
|
|
||||||
backgroundColor: '#525252',
|
|
||||||
marginBottom: 10,
|
|
||||||
},
|
|
||||||
image: imageStyle(settings),
|
|
||||||
});
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
src: string
|
src: string
|
||||||
index: number
|
index: number
|
||||||
@@ -84,7 +68,6 @@ const Page = React.forwardRef((props: IProps, ref: any) => {
|
|||||||
|
|
||||||
const [useCache] = useLocalStorage<boolean>('useCache', true);
|
const [useCache] = useLocalStorage<boolean>('useCache', true);
|
||||||
|
|
||||||
const classes = useStyles(settings)();
|
|
||||||
const imgRef = useRef<HTMLImageElement>(null);
|
const imgRef = useRef<HTMLImageElement>(null);
|
||||||
|
|
||||||
const handleVerticalScroll = () => {
|
const handleVerticalScroll = () => {
|
||||||
@@ -120,17 +103,26 @@ const Page = React.forwardRef((props: IProps, ref: any) => {
|
|||||||
}
|
}
|
||||||
}, [handleVerticalScroll]);
|
}, [handleVerticalScroll]);
|
||||||
|
|
||||||
|
const imgStyle = imageStyle(settings);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={ref} style={{ margin: 'auto' }}>
|
<Box ref={ref} sx={{ margin: 'auto' }}>
|
||||||
<SpinnerImage
|
<SpinnerImage
|
||||||
src={`${src}?useCache=${useCache}`}
|
src={`${src}?useCache=${useCache}`}
|
||||||
onImageLoad={onImageLoad}
|
onImageLoad={onImageLoad}
|
||||||
alt={`Page #${index}`}
|
alt={`Page #${index}`}
|
||||||
imgRef={imgRef}
|
imgRef={imgRef}
|
||||||
spinnerClassName={`${classes.image} ${classes.loadingImage}`}
|
spinnerStyle={{
|
||||||
imgClassName={classes.image}
|
...imgStyle,
|
||||||
|
height: '100vh',
|
||||||
|
width: '70vw',
|
||||||
|
padding: '50px calc(50% - 20px)',
|
||||||
|
backgroundColor: '#525252',
|
||||||
|
marginBottom: 10,
|
||||||
|
}}
|
||||||
|
imgStyle={imgStyle}
|
||||||
/>
|
/>
|
||||||
</div>
|
</Box>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ interface IProps {
|
|||||||
|
|
||||||
imgRef?: React.RefObject<HTMLImageElement>
|
imgRef?: React.RefObject<HTMLImageElement>
|
||||||
|
|
||||||
spinnerClassName?: string
|
|
||||||
spinnerStyle?: SxProps<Theme>
|
spinnerStyle?: SxProps<Theme>
|
||||||
imgClassName?: string
|
|
||||||
imgStyle?: CSSProperties
|
imgStyle?: CSSProperties
|
||||||
|
|
||||||
onImageLoad?: () => void
|
onImageLoad?: () => void
|
||||||
@@ -27,7 +25,7 @@ interface IProps {
|
|||||||
|
|
||||||
export default function SpinnerImage(props: IProps) {
|
export default function SpinnerImage(props: IProps) {
|
||||||
const {
|
const {
|
||||||
src, alt, onImageLoad, imgRef, spinnerClassName, imgClassName, spinnerStyle, imgStyle,
|
src, alt, onImageLoad, imgRef, spinnerStyle, imgStyle,
|
||||||
} = props;
|
} = props;
|
||||||
const [imageSrc, setImagsrc] = useState<string>('');
|
const [imageSrc, setImagsrc] = useState<string>('');
|
||||||
|
|
||||||
@@ -53,19 +51,18 @@ export default function SpinnerImage(props: IProps) {
|
|||||||
|
|
||||||
if (imageSrc.length === 0) {
|
if (imageSrc.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Box className={spinnerClassName} sx={spinnerStyle}>
|
<Box sx={spinnerStyle}>
|
||||||
<CircularProgress thickness={5} />
|
<CircularProgress thickness={5} />
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageSrc === 'Not Found') {
|
if (imageSrc === 'Not Found') {
|
||||||
return <Box className={spinnerClassName} sx={spinnerStyle} />;
|
return <Box sx={spinnerStyle} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
className={imgClassName}
|
|
||||||
style={imgStyle}
|
style={imgStyle}
|
||||||
ref={imgRef}
|
ref={imgRef}
|
||||||
src={imageSrc}
|
src={imageSrc}
|
||||||
@@ -75,8 +72,6 @@ export default function SpinnerImage(props: IProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpinnerImage.defaultProps = {
|
SpinnerImage.defaultProps = {
|
||||||
spinnerClassName: '',
|
|
||||||
imgClassName: '',
|
|
||||||
spinnerStyle: {},
|
spinnerStyle: {},
|
||||||
imgStyle: {},
|
imgStyle: {},
|
||||||
onImageLoad: () => {},
|
onImageLoad: () => {},
|
||||||
|
|||||||
Reference in New Issue
Block a user