2024-10-19 19:52:28 +02:00
|
|
|
import React, {EventHandler, MouseEventHandler, ReactElement, useEffect, useState} from 'react';
|
2024-10-18 19:46:17 +02:00
|
|
|
import {Job} from './Job';
|
|
|
|
import '../styles/monitorMangaList.css';
|
|
|
|
import IJob from "./interfaces/IJob";
|
2024-10-19 19:52:28 +02:00
|
|
|
import IManga, {CoverCard} from "./interfaces/IManga";
|
2024-10-18 19:46:17 +02:00
|
|
|
import {Manga} from './Manga';
|
2024-10-19 19:52:28 +02:00
|
|
|
import '../styles/MangaCoverCard.css'
|
2024-10-18 19:46:17 +02:00
|
|
|
|
2024-10-19 19:52:28 +02:00
|
|
|
export default function MonitorJobsList({onStartSearch, onJobsChanged} : {onStartSearch() : void, onJobsChanged: EventHandler<any>}) {
|
|
|
|
const [MonitoringJobs, setMonitoringJobs] = useState<IJob[]>([]);
|
|
|
|
const [AllManga, setAllManga] = useState<IManga[]>([]);
|
2024-10-18 19:46:17 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-10-19 19:52:28 +02:00
|
|
|
console.debug("Updating display list.");
|
2024-10-18 19:46:17 +02:00
|
|
|
//Remove all Manga that are not associated with a Job
|
|
|
|
setAllManga(AllManga.filter(manga => MonitoringJobs.find(job => job.mangaInternalId == manga.internalId)));
|
|
|
|
//Fetch Manga that are missing (from Jobs)
|
|
|
|
if(MonitoringJobs === null)
|
|
|
|
return;
|
|
|
|
MonitoringJobs.forEach(job => {
|
|
|
|
if(AllManga.find(manga => manga.internalId == job.mangaInternalId))
|
|
|
|
return;
|
|
|
|
Manga.GetMangaById(job.mangaInternalId).then((manga: IManga) => setAllManga([...AllManga, manga]));
|
|
|
|
});
|
|
|
|
}, [MonitoringJobs]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
UpdateMonitoringJobsList();
|
|
|
|
}, []);
|
|
|
|
|
2024-10-19 19:52:28 +02:00
|
|
|
const DeleteJob : MouseEventHandler = (e) => {
|
2024-10-18 19:46:17 +02:00
|
|
|
const jobId = e.currentTarget.id;
|
2024-10-19 19:52:28 +02:00
|
|
|
Job.DeleteJob(jobId).then(() => onJobsChanged(jobId));
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpdateMonitoringJobsList(){
|
|
|
|
console.debug("Updating MonitoringJobsList");
|
|
|
|
Job.GetMonitoringJobs()
|
|
|
|
.then((jobs) => {
|
|
|
|
if(jobs.length > 0)
|
|
|
|
return Job.GetJobs(jobs)
|
|
|
|
return [];
|
|
|
|
})
|
|
|
|
.then((jobs) => setMonitoringJobs(jobs));
|
2024-10-18 19:46:17 +02:00
|
|
|
}
|
|
|
|
|
2024-10-19 16:28:49 +02:00
|
|
|
function StartSearchMangaEntry() : ReactElement {
|
|
|
|
return (<div key="monitorMangaEntry.StartSearch" className="monitorMangaEntry" onClick={onStartSearch}>
|
|
|
|
<div className="Manga" key="StartSearch.Manga">
|
|
|
|
<img src="../media/blahaj.png"></img>
|
|
|
|
<div>
|
|
|
|
<p style={{textAlign: "center", width: "100%"}} className="Manga-name">Add new Manga</p>
|
|
|
|
<p style={{fontSize: "42pt", textAlign: "center"}}>+</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
|
2024-10-18 19:46:17 +02:00
|
|
|
return (
|
|
|
|
<div id="MonitorMangaList">
|
2024-10-19 16:28:49 +02:00
|
|
|
{StartSearchMangaEntry()}
|
2024-10-18 19:46:17 +02:00
|
|
|
{AllManga.map((manga: IManga) => {
|
|
|
|
const job = MonitoringJobs.find(job => job.mangaInternalId == manga.internalId);
|
2024-10-19 16:28:49 +02:00
|
|
|
if (job === undefined || job == null)
|
2024-10-18 19:46:17 +02:00
|
|
|
return <div>Error. Could not find matching job for {manga.internalId}</div>
|
|
|
|
return <div key={"monitorMangaEntry." + manga.internalId} className="monitorMangaEntry">
|
2024-10-19 19:52:28 +02:00
|
|
|
{CoverCard(manga)}
|
2024-10-18 19:46:17 +02:00
|
|
|
{job.id}
|
|
|
|
<button id={job.id} onClick={DeleteJob}>Delete</button>
|
|
|
|
</div>;
|
|
|
|
})}
|
|
|
|
</div>)
|
|
|
|
}
|