Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the Floating action button to Resume to the last read chapter #59

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 21 additions & 42 deletions src/components/ChapterCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import React from 'react';
import { useTheme } from '@mui/material/styles';
import makeStyles from '@mui/styles/makeStyles';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import IconButton from '@mui/material/IconButton';
Expand All @@ -19,51 +18,13 @@ import MenuItem from '@mui/material/MenuItem';
import BookmarkIcon from '@mui/icons-material/Bookmark';
import client from 'util/client';

const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
},
bullet: {
display: 'inline-block',
margin: '0 2px',
transform: 'scale(0.8)',
},
title: {
fontSize: 14,
},
pos: {
marginBottom: 12,
},
icon: {
width: theme.spacing(7),
height: theme.spacing(7),
flex: '0 0 auto',
marginRight: 16,
},
card: {
margin: '10px',
'&:hover': {
backgroundColor: theme.palette.action.hover,
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
},
'&:active': {
backgroundColor: theme.palette.action.selected,
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
},
},
}));

interface IProps{
chapter: IChapter
triggerChaptersUpdate: () => void
downloadStatusString: string
}

export default function ChapterCard(props: IProps) {
const classes = useStyles();
const theme = useTheme();
const { chapter, triggerChaptersUpdate, downloadStatusString } = props;

Expand All @@ -84,6 +45,7 @@ export default function ChapterCard(props: IProps) {

const formData = new FormData();
formData.append(key, value);
if (key === 'read') { formData.append('lastPageRead', '1'); }
client.patch(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`, formData)
.then(() => triggerChaptersUpdate());
};
Expand All @@ -104,8 +66,25 @@ export default function ChapterCard(props: IProps) {
return (
<>
<li>
<Card className={classes.card}>
<CardContent className={classes.root}>
<Card sx={{
margin: '10px',
':hover': {
backgroundColor: 'action.hover',
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
},
':active': {
backgroundColor: 'action.selected',
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
},
}}
>
<CardContent sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: 2,
}}
>
<Link
to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`}
style={{
Expand Down Expand Up @@ -149,7 +128,7 @@ export default function ChapterCard(props: IProps) {
{!chapter.bookmarked && 'Bookmark'}
</MenuItem>
<MenuItem onClick={() => sendChange('read', !chapter.read)}>
{`Mark as ${chapter.read && 'unread'} ${!chapter.read && 'read'}`}
{`Mark as ${chapter.read ? 'unread' : 'read'}`}
</MenuItem>
<MenuItem onClick={() => sendChange('markPrevRead', true)}>
Mark previous as Read
Expand Down
25 changes: 23 additions & 2 deletions src/screens/Manga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import React, { useEffect, useState, useContext } from 'react';
import { Theme } from '@mui/material/styles';
import makeStyles from '@mui/styles/makeStyles';
import { useParams } from 'react-router-dom';
import { Link, useParams } from 'react-router-dom';
import { Virtuoso } from 'react-virtuoso';
import ChapterCard from 'components/ChapterCard';
import MangaDetails from 'components/MangaDetails';
import NavbarContext from 'components/context/NavbarContext';
import client from 'util/client';
import LoadingPlaceholder from 'components/util/LoadingPlaceholder';
import makeToast from 'components/util/Toast';
import { Fab } from '@mui/material';
import PlayArrow from '@mui/icons-material/PlayArrow';

const useStyles = makeStyles((theme: Theme) => ({
root: {
Expand Down Expand Up @@ -62,6 +64,7 @@ export default function Manga() {
const [chapterUpdateTriggerer, setChapterUpdateTriggerer] = useState(0);
const [fetchedOnline, setFetchedOnline] = useState(false);
const [fetchedOffline, setFetchedOffline] = useState(false);
const [firstUnreadChapter, setFirstUnreadChapter] = useState<IChapter>();

const [, setWsClient] = useState<WebSocket>();
const [{ queue }, setQueueState] = useState<IQueue>(initialQueue);
Expand Down Expand Up @@ -129,6 +132,24 @@ export default function Manga() {
});
}, [fetchedOnline, fetchedOffline, chapterUpdateTriggerer]);

useEffect(() => {
const a = [...chapters].reverse().find((chp) => !chp.read);
setFirstUnreadChapter(a);
}, [chapters]);

const resumeButton = () => firstUnreadChapter && (
<Fab
sx={{ position: 'fixed', bottom: '5vw', right: '5vw' }}
component={Link}
variant="extended"
color="primary"
to={`/manga/${id}/chapter/${firstUnreadChapter.index}/page/${firstUnreadChapter.lastPageRead}`}
>
<PlayArrow />
{firstUnreadChapter.index === 1 ? 'Start' : 'Resume' }
</Fab>
);

return (
<div className={classes.root}>
<LoadingPlaceholder
Expand Down Expand Up @@ -158,7 +179,7 @@ export default function Manga() {
overscan={window.innerHeight * 0.5}
/>
</LoadingPlaceholder>

{resumeButton()}
AriaMoradi marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
}
1 change: 1 addition & 0 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface IChapter {
read: boolean
bookmarked: boolean
lastPageRead: number
lastReadAt: number
index: number
fetchedAt: number
chapterCount: number
Expand Down