support bookmarked and isRead in webUI

This commit is contained in:
Aria Moradi 2021-05-14 19:22:10 +04:30
parent da6a953099
commit 866b01f865
2 changed files with 19 additions and 13 deletions

View File

@ -167,6 +167,7 @@ object Chapter {
fun modifyChapter(mangaId: Int, chapterIndex: Int, isRead: Boolean?, isBookmarked: Boolean?, markPrevRead: Boolean?, lastPageRead: Int?) { fun modifyChapter(mangaId: Int, chapterIndex: Int, isRead: Boolean?, isBookmarked: Boolean?, markPrevRead: Boolean?, lastPageRead: Int?) {
transaction { transaction {
if (listOf(isRead, isBookmarked, lastPageRead).any { it != null }) {
ChapterTable.update({ (ChapterTable.manga eq mangaId) and (ChapterTable.chapterIndex eq chapterIndex) }) { update -> ChapterTable.update({ (ChapterTable.manga eq mangaId) and (ChapterTable.chapterIndex eq chapterIndex) }) { update ->
isRead?.also { isRead?.also {
update[ChapterTable.isRead] = it update[ChapterTable.isRead] = it
@ -178,6 +179,7 @@ object Chapter {
update[ChapterTable.lastPageRead] = it update[ChapterTable.lastPageRead] = it
} }
} }
}
markPrevRead?.let { markPrevRead?.let {
ChapterTable.update({ (ChapterTable.manga eq mangaId) and (ChapterTable.chapterIndex less chapterIndex) }) { ChapterTable.update({ (ChapterTable.manga eq mangaId) and (ChapterTable.chapterIndex less chapterIndex) }) {

View File

@ -16,6 +16,7 @@ import Typography from '@material-ui/core/Typography';
import { Link, useHistory } from 'react-router-dom'; import { Link, useHistory } from 'react-router-dom';
import Menu from '@material-ui/core/Menu'; import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import BookmarkIcon from '@material-ui/icons/Bookmark';
import client from '../util/client'; import client from '../util/client';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
@ -25,6 +26,9 @@ const useStyles = makeStyles((theme) => ({
alignItems: 'center', alignItems: 'center',
padding: 16, padding: 16,
}, },
read: {
backgroundColor: theme.palette.type === 'dark' ? '#353535' : '#f0f0f0',
},
bullet: { bullet: {
display: 'inline-block', display: 'inline-block',
margin: '0 2px', margin: '0 2px',
@ -73,15 +77,13 @@ export default function ChapterCard(props: IProps) {
const formData = new FormData(); const formData = new FormData();
formData.append(key, value); formData.append(key, value);
client.patch(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`, formData); client.patch(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`, formData);
// .finally(() => triggerUpdate()
// );
}; };
return ( return (
<> <>
<li> <li>
<Card> <Card>
<CardContent className={classes.root}> <CardContent className={`${classes.root} ${chapter.read && classes.read}`}>
<Link <Link
to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`} to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`}
style={{ style={{
@ -91,8 +93,10 @@ export default function ChapterCard(props: IProps) {
> >
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
<div style={{ display: 'flex', flexDirection: 'column' }}> <div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h5" component="h2"> <Typography variant="h5" component="h2">
<span style={{ color: theme.palette.primary.dark }}>
{chapter.bookmarked && <BookmarkIcon />}
</span>
{chapter.name} {chapter.name}
{chapter.chapterNumber > 0 && ` : ${chapter.chapterNumber}`} {chapter.chapterNumber > 0 && ` : ${chapter.chapterNumber}`}
</Typography> </Typography>