import React, {useEffect, useState} from 'react'; import IJob, {JobTypeFromNumber} from "./interfaces/IJob"; import '../styles/queuePopUp.css'; import '../styles/popup.css'; import {Job} from "./Job"; import IManga from "./interfaces/IManga"; import {Manga} from "./Manga"; export default function QueuePopUp({children} : {children: JSX.Element[]}) { const [StandbyJobs, setStandbyJobs] = React.useState([]); const [StandbyJobsManga, setStandbyJobsManga] = React.useState([]); const [RunningJobs, setRunningJobs] = React.useState([]); const [RunningJobsManga, setRunningJobsManga] = React.useState([]); const [showQueuePopup, setShowQueuePopup] = useState(false); useEffect(() => { Job.GetStandbyJobs() .then((jobs) => { if(jobs.length > 0) return Job.GetJobs(jobs); return []; }) .then((jobs) => { console.debug("Removing Metadata Jobs"); console.log(StandbyJobs) setStandbyJobs(jobs.filter(job => job.jobType <= 1)); console.log(StandbyJobs) }); Job.GetRunningJobs() .then((jobs) => { if(jobs.length > 0) return Job.GetJobs(jobs); return []; }) .then((jobs) =>{ console.debug("Removing Metadata Jobs"); setRunningJobs(jobs.filter(job => job.jobType <= 1)); }); }, []); useEffect(() => { if(StandbyJobs.length < 1) return; const mangaIds = StandbyJobs.filter(job => job.jobType<=2).map((job) => job.mangaInternalId != undefined ? job.mangaInternalId : job.chapter != undefined ? job.chapter.parentManga.internalId : ""); console.debug(`Waiting mangaIds: ${mangaIds.join(",")}`); Manga.GetMangaByIds(mangaIds) .then(setStandbyJobsManga); }, [StandbyJobs]); useEffect(() => { if(RunningJobs.length < 1) return; console.log(RunningJobs); const mangaIds = RunningJobs.filter(job => job.jobType<=2).map((job) => job.mangaInternalId != undefined ? job.mangaInternalId : job.chapter != undefined ? job.chapter.parentManga.internalId : ""); console.debug(`Running mangaIds: ${mangaIds.join(",")}`); Manga.GetMangaByIds(mangaIds) .then(setRunningJobsManga); }, [RunningJobs]); return (<>
setShowQueuePopup(true)}> {children}
{showQueuePopup ?

Queue Status {showQueuePopup ? "true" : "false"}

Close Search setShowQueuePopup(false)}/>

Running

{RunningJobs.map((job: IJob) => { const manga = RunningJobsManga.find(manga => manga.internalId == job.mangaInternalId || manga.internalId == job.chapter?.parentManga.internalId); if (manga === undefined || manga === null) return
Error. Could not find matching manga for {job.id}
return

{JobTypeFromNumber(job.jobType)}

; })}

Standby

{StandbyJobs.map((job: IJob) => { const manga = StandbyJobsManga.find(manga => manga.internalId == job.mangaInternalId || manga.internalId == job.chapter?.parentManga.internalId); if (manga === undefined || manga === null) return
Error. Could not find matching manga for {job.id}
return

{manga.sortName}

{JobTypeFromNumber(job.jobType)}

{job.jobType == 0 ? `Vol.${job.chapter?.volumeNumber} Ch.${job.chapter?.chapterNumber}` : ""}

; })}
: <> } ); }