handle front, handle orphans

This commit is contained in:
Aria Moradi 2021-05-11 18:45:53 +04:30
parent 8abb132ad6
commit c200785479
3 changed files with 17 additions and 8 deletions

View File

@ -17,6 +17,7 @@ import ir.armor.tachidesk.model.database.table.MangaTable
import ir.armor.tachidesk.model.database.table.PageTable import ir.armor.tachidesk.model.database.table.PageTable
import ir.armor.tachidesk.model.dataclass.ChapterDataClass import ir.armor.tachidesk.model.dataclass.ChapterDataClass
import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.selectAll
@ -69,16 +70,22 @@ object Chapter {
val dbChapterCount = transaction { ChapterTable.selectAll().count() } val dbChapterCount = transaction { ChapterTable.selectAll().count() }
if (dbChapterCount > chapterCount) { // we got some clean up due if (dbChapterCount > chapterCount) { // we got some clean up due
// TODO: delete orphan chapters // TODO: delete orphan chapters
val dbChapterList = transaction { ChapterTable.selectAll().orderBy() } val dbChapterList = transaction { ChapterTable.selectAll() }
dbChapterList.forEach {
(it[ChapterTable.chapterIndex] >= chapterList.size
|| chapterList[it[ChapterTable.chapterIndex]].url != it[ChapterTable.url])
ChapterTable.deleteWhere { ChapterTable.id eq it[ChapterTable.id] }
}
} }
val dbChapters = transaction { ChapterTable.selectAll() } val dbChapterMap = transaction { ChapterTable.selectAll() }
.associateBy({ it[ChapterTable.url] }, { it }) .associateBy({ it[ChapterTable.url] }, { it })
chapterList.mapIndexed { index, it -> chapterList.mapIndexed { index, it ->
val dbChapter = dbChapters.getValue(it.url) val dbChapter = dbChapterMap.getValue(it.url)
ChapterDataClass( ChapterDataClass(
it.url, it.url,
@ -138,7 +145,6 @@ object Chapter {
} }
} }
return ChapterDataClass( return ChapterDataClass(
chapterEntry[ChapterTable.url], chapterEntry[ChapterTable.url],
chapterEntry[ChapterTable.name], chapterEntry[ChapterTable.name],

View File

@ -49,7 +49,7 @@ export default function ChapterCard(props: IProps) {
const history = useHistory(); const history = useHistory();
const { chapter } = props; const { chapter } = props;
const dateStr = chapter.date_upload && new Date(chapter.date_upload).toISOString().slice(0, 10); const dateStr = chapter.uploadDate && new Date(chapter.uploadDate).toISOString().slice(0, 10);
return ( return (
<> <>
@ -60,7 +60,7 @@ export default function ChapterCard(props: IProps) {
<div style={{ display: 'flex', flexDirection: 'column' }}> <div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h5" component="h2"> <Typography variant="h5" component="h2">
{chapter.name} {chapter.name}
{chapter.chapter_number > 0 && ` : ${chapter.chapter_number}`} {chapter.chapterNumber > 0 && ` : ${chapter.chapterNumber}`}
</Typography> </Typography>
<Typography variant="caption" display="block" gutterBottom> <Typography variant="caption" display="block" gutterBottom>
{chapter.scanlator} {chapter.scanlator}

View File

@ -56,10 +56,13 @@ interface IChapter {
id: number id: number
url: string url: string
name: string name: string
date_upload: number uploadDate: number
chapter_number: number chapterNumber: number
scanlator: String scanlator: String
mangaId: number mangaId: number
read: boolean
bookmarked: boolean
lastPageRead: number
chapterIndex: number chapterIndex: number
chapterCount: number chapterCount: number
pageCount: number pageCount: number