Skip to content

Commit

Permalink
add support for useCache
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaMoradi committed Sep 18, 2021
1 parent 344f4e8 commit 03e7d49
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/manga/ExtensionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default function ExtensionCard(props: IProps) {
);

const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
const [useCache] = useLocalStorage<boolean>('useCache', true);

const classes = useStyles();
const langPress = lang === 'all' ? 'All' : lang.toUpperCase();
Expand Down Expand Up @@ -124,7 +125,7 @@ export default function ExtensionCard(props: IProps) {
variant="rounded"
className={classes.icon}
alt={name}
src={serverAddress + iconUrl}
src={`${serverAddress}${iconUrl}?useCache=${useCache}`}
/>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h5" component="h2">
Expand Down
3 changes: 2 additions & 1 deletion src/components/manga/MangaCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const MangaCard = React.forwardRef<HTMLDivElement, IProps>((props: IProps, ref)
} = props;
const classes = useStyles();
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
const [useCache] = useLocalStorage<boolean>('useCache', true);

return (
<Grid item xs={6} sm={4} md={3} lg={2}>
Expand All @@ -83,7 +84,7 @@ const MangaCard = React.forwardRef<HTMLDivElement, IProps>((props: IProps, ref)
<div className={classes.wrapper}>
<SpinnerImage
alt={title}
src={serverAddress + thumbnailUrl}
src={`${serverAddress}${thumbnailUrl}?useCache=${useCache}`}
spinnerClassName={classes.spinner}
imgClassName={classes.image}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/manga/MangaDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export default function MangaDetails(props: IProps) {
}, [inLibrary, categoryDialogOpen]);

const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
const [useCache] = useLocalStorage<boolean>('useCache', true);

const classes = useStyles(inLibrary)();

Expand Down Expand Up @@ -197,7 +198,7 @@ export default function MangaDetails(props: IProps) {
<div className={classes.top}>
<div className={classes.leftRight}>
<div className={classes.leftSide}>
<img src={`${serverAddress}${manga.thumbnailUrl}`} alt="Manga Thumbnail" />
<img src={`${serverAddress}${manga.thumbnailUrl}?useCache=${useCache}`} alt="Manga Thumbnail" />
</div>
<div className={classes.rightSide}>
<h1>
Expand Down
3 changes: 2 additions & 1 deletion src/components/manga/SourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default function SourceCard(props: IProps) {
const history = useHistory();

const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
const [useCache] = useLocalStorage<boolean>('useCache', true);

const classes = useStyles();

Expand All @@ -104,7 +105,7 @@ export default function SourceCard(props: IProps) {
variant="rounded"
className={classes.icon}
alt={name}
src={serverAddress + iconUrl}
src={`${serverAddress}${iconUrl}?useCache=${useCache}`}
/>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h5" component="h2">
Expand Down
5 changes: 4 additions & 1 deletion src/components/manga/reader/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import makeStyles from '@mui/styles/makeStyles';
import React, { useEffect, useRef } from 'react';
import SpinnerImage from 'components/SpinnerImage';
import useLocalStorage from 'util/useLocalStorage';

function imageStyle(settings: IReaderSettings): any {
if (settings.readerType === 'DoubleLTR'
Expand Down Expand Up @@ -65,6 +66,8 @@ const Page = React.forwardRef((props: IProps, ref: any) => {
src, index, onImageLoad, setCurPage, settings,
} = props;

const [useCache] = useLocalStorage<boolean>('useCache', true);

const classes = useStyles(settings)();
const imgRef = useRef<HTMLImageElement>(null);

Expand Down Expand Up @@ -104,7 +107,7 @@ const Page = React.forwardRef((props: IProps, ref: any) => {
return (
<div ref={ref} style={{ margin: '0 auto' }}>
<SpinnerImage
src={src}
src={`${src}?useCache=${useCache}`}
onImageLoad={onImageLoad}
alt={`Page #${index}`}
imgRef={imgRef}
Expand Down
24 changes: 23 additions & 1 deletion src/screens/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Brightness6Icon from '@mui/icons-material/Brightness6';
import DnsIcon from '@mui/icons-material/Dns';
import EditIcon from '@mui/icons-material/Edit';
import InfoIcon from '@mui/icons-material/Info';
import CachedIcon from '@mui/icons-material/Cached';
import ListItem from '@mui/material/ListItem';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
Expand All @@ -38,6 +39,7 @@ export default function Settings() {
const { darkTheme, setDarkTheme } = useContext(DarkTheme);
const [serverAddress, setServerAddress] = useLocalStorage<String>('serverBaseURL', '');
const [showNsfw, setShowNsfw] = useLocalStorage<boolean>('showNsfw', true);
const [useCache, setUseCache] = useLocalStorage<boolean>('useCache', true);
const [dialogOpen, setDialogOpen] = useState(false);
const [dialogValue, setDialogValue] = useState(serverAddress);

Expand Down Expand Up @@ -87,7 +89,10 @@ export default function Settings() {
<ListItemIcon>
<FavoriteIcon />
</ListItemIcon>
<ListItemText primary="Show NSFW" />
<ListItemText
primary="Show NSFW"
secondary="Hide NSFW extensions and sources"
/>
<ListItemSecondaryAction>
<Switch
edge="end"
Expand All @@ -96,6 +101,23 @@ export default function Settings() {
/>
</ListItemSecondaryAction>
</ListItem>
<ListItem>
<ListItemIcon>
<CachedIcon />
</ListItemIcon>
<ListItemText
primary="Use image cache"
secondary="Disabling image cache makes images load faster if you have a slow disk,
but uses it much more internet traffic in turn"
/>
<ListItemSecondaryAction>
<Switch
edge="end"
checked={useCache}
onChange={() => setUseCache(!useCache)}
/>
</ListItemSecondaryAction>
</ListItem>
<ListItem>
<ListItemIcon>
<DnsIcon />
Expand Down

0 comments on commit 03e7d49

Please sign in to comment.