add chapter list

This commit is contained in:
Aria Moradi 2021-01-19 21:02:57 +03:30
parent 0b2d49f3f6
commit 9f75087f20
7 changed files with 82 additions and 23 deletions

View File

@ -76,6 +76,11 @@ class Main {
ctx.json(getManga(mangaId)) ctx.json(getManga(mangaId))
} }
app.get("/api/v1/chapters/:mangaId/") { ctx ->
val mangaId = ctx.pathParam("mangaId").toInt()
ctx.json(getChapterList(mangaId))
}
} }

View File

@ -0,0 +1,9 @@
package ir.armor.tachidesk.database.dataclass
data class ChapterDataClass(
val url: String,
val name: String,
val date_upload: String,
val chapter_number: Float,
val scanlator: String?,
)

View File

@ -1,10 +1,10 @@
package ir.armor.tachidesk.util package ir.armor.tachidesk.util
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import ir.armor.tachidesk.database.dataclass.ChapterDataClass
import ir.armor.tachidesk.database.dataclass.MangaDataClass import ir.armor.tachidesk.database.dataclass.MangaDataClass
import ir.armor.tachidesk.database.table.MangaStatus import ir.armor.tachidesk.database.table.MangaStatus
import ir.armor.tachidesk.database.table.MangaTable import ir.armor.tachidesk.database.table.MangaTable
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update import org.jetbrains.exposed.sql.update
@ -75,6 +75,26 @@ fun getManga(mangaId: Int): MangaDataClass {
) )
} }
} }
}
fun getChapterList(mangaId: Int): List<ChapterDataClass> {
val mangaDetails = getManga(mangaId)
val source = getHttpSource(mangaDetails.sourceId)
val chapterList = source.fetchChapterList(
SManga.create().apply {
title = mangaDetails.title
url = mangaDetails.url
}
).toBlocking().first()
return chapterList.map {
ChapterDataClass(
it.url,
it.name,
it.date_upload.toString(),
it.chapter_number,
it.scanlator,
)
}
} }

View File

@ -31,12 +31,13 @@ const useStyles = makeStyles((theme) => ({
}, },
})); }));
export default function ChapterCard() { interface IProps{
const name = 'Chapter 1'; chapter: IChapter
const relaseDate = '16/01/21'; }
// const downloaded = false;
// const downloadedText = downloaded ? 'open' : 'download'; export default function ChapterCard(props: IProps) {
const classes = useStyles(); const classes = useStyles();
const { chapter } = props;
return ( return (
<> <>
@ -46,10 +47,14 @@ export default function ChapterCard() {
<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">
{name} {chapter.name}
{chapter.chapter_number > 0 && ` : ${chapter.chapter_number}`}
</Typography> </Typography>
<Typography variant="caption" display="block" gutterBottom> <Typography variant="caption" display="block" gutterBottom>
{relaseDate} {chapter.scanlator}
{chapter.scanlator && ' '}
{chapter.date_upload
&& new Date(chapter.date_upload).toISOString().slice(0, 10)}
</Typography> </Typography>
</div> </div>
</div> </div>

View File

@ -1,18 +1,11 @@
import React, { useEffect, useState } from 'react'; import React from 'react';
interface IProps{ interface IProps{
id: string manga: IManga | undefined
} }
export default function MangaDetails(props: IProps) { export default function MangaDetails(props: IProps) {
const { id } = props; const { manga } = props;
const [manga, setManga] = useState<IManga>();
useEffect(() => {
fetch(`http://127.0.0.1:4567/api/v1/manga/${id}/`)
.then((response) => response.json())
.then((data) => setManga(data));
}, []);
return ( return (
<> <>

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import ChapterCard from '../components/ChapterCard'; import ChapterCard from '../components/ChapterCard';
import MangaDetails from '../components/MangaDetails'; import MangaDetails from '../components/MangaDetails';
@ -6,12 +6,31 @@ import MangaDetails from '../components/MangaDetails';
export default function Manga() { export default function Manga() {
const { id } = useParams<{id: string}>(); const { id } = useParams<{id: string}>();
const [manga, setManga] = useState<IManga>();
const [chapters, setChapters] = useState<IChapter[]>([]);
useEffect(() => {
fetch(`http://127.0.0.1:4567/api/v1/manga/${id}/`)
.then((response) => response.json())
.then((data) => setManga(data));
}, []);
useEffect(() => {
fetch(`http://127.0.0.1:4567/api/v1/chapters/${id}/`)
.then((response) => response.json())
.then((data) => setChapters(data));
}, []);
const chapterCards = chapters.map((chapter) => (
<ol style={{ listStyle: 'none', padding: 0 }}>
<ChapterCard chapter={chapter} />
</ol>
));
return ( return (
<> <>
<MangaDetails id={id} /> <MangaDetails manga={manga} />
<ol style={{ listStyle: 'none', padding: 0 }}> {chapterCards}
<ChapterCard />
</ol>
</> </>
); );
} }

View File

@ -21,3 +21,11 @@ interface IManga {
title: string title: string
thumbnailUrl: string thumbnailUrl: string
} }
interface IChapter {
url: string
name: string
date_upload: string
chapter_number: number
scanlator: String
}