import Manga from "../api/Manga"; import React, {Children, ReactElement, ReactEventHandler, useEffect, useState} from "react"; import Icon from '@mdi/react'; import { mdiTagTextOutline, mdiAccountEdit, mdiLinkVariant } from '@mdi/js'; import MarkdownPreview from '@uiw/react-markdown-preview'; import Loader from "../Loader"; import IManga from "../types/IManga"; import IChapter from "../types/IChapter"; import AuthorElement from "./Author"; import LinkElement from "./Link"; export default function MangaItem({apiUri, mangaId, children} : {apiUri: string, mangaId: string, children?: (string | ReactElement)[]}) : ReactElement { const LoadMangaCover : ReactEventHandler = (e) => { if(e.currentTarget.src != Manga.GetMangaCoverImageUrl(apiUri, mangaId, e.currentTarget)) e.currentTarget.src = Manga.GetMangaCoverImageUrl(apiUri, mangaId, e.currentTarget); } let [manga, setManga] = useState(null); let [clicked, setClicked] = useState(false); let [latestChapterDownloaded, setLatestChapterDownloaded] = useState(null); let [latestChapterAvailable, setLatestChapterAvailable] = useState(null); let [loadingChapterStats, setLoadingChapterStats] = useState(true); let [settingThreshold, setSettingThreshold] = useState(false); const invalidTargets = ["input", "textarea", "button", "select", "a"]; useEffect(() => { Manga.GetMangaById(apiUri, mangaId).then(setManga); Manga.GetLatestChapterDownloaded(apiUri, mangaId) .then(setLatestChapterDownloaded) .finally(() => { if(latestChapterDownloaded && latestChapterAvailable) setLoadingChapterStats(false); }); Manga.GetLatestChapterAvailable(apiUri, mangaId) .then(setLatestChapterAvailable) .finally(() => { if(latestChapterDownloaded && latestChapterAvailable) setLoadingChapterStats(false); }); }, []); return (
{ e.preventDefault(); const target = e.target as HTMLElement; if(invalidTargets.find(x => x == target.localName) === undefined ) setClicked(!clicked) }}> Manga Cover
{manga ? manga.mangaConnectorId : "Connector"}
{manga ? manga.name : "Name"}
Link
{manga ? manga.authorIds.map(authorId =>
) :
} {manga ? manga.tags.map(tag =>
{tag}
) :
Tag
} {manga ? manga.linkIds.map(linkId =>
) :
}
Start at Chapter { setSettingThreshold(true); Manga.SetIgnoreThreshold(apiUri, mangaId, e.currentTarget.valueAsNumber).finally(()=>setSettingThreshold(false)); }} /> out of {latestChapterAvailable ? latestChapterAvailable.chapterNumber : }
{children ? children.map(c => { if(c instanceof Element) return c as ReactElement; else return c }) : null}
) }