Skip to content

Commit

Permalink
fix(Collectionner): 🐛 Fixing some bugs on the details/series buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytuo committed Sep 9, 2023
1 parent 92e9e16 commit c9538a6
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 58 deletions.
2 changes: 1 addition & 1 deletion public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"NumberComics": "Nombre de bandes dessinées dans cette série ",
"NumberChapter": "Nombre de chapitre dans cette série ",
"ThisseriesIDfromMarvel": "Cette série ID de Marvel",
"RELEASING": "LIBERTE",
"RELEASING": "EN COURS",
"FINISHED": "FINI",
"NOTYETRELEASED": "PAS ENCORE PUBLIÉ",
"ENDSOON": "FIN BIENTÔT",
Expand Down
1 change: 1 addition & 0 deletions src/API/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class API {
* @param {boolean} isSeries Is the element a series
*/
async rematch(new_id: string, provider: number, type: string, old_id: string, isSeries = false) {
logger.info("Rematching " + old_id + " to " + new_id + " from " + provider + " (" + type + ")");
await fetch(PDP + "/DB/update", {
method: "POST", headers: {
"Content-Type": "application/json"
Expand Down
6 changes: 3 additions & 3 deletions src/API/OpenLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class OpenLibrary {
return fetch(PDP + "/api/ol/getComics/" + name).then(function (response) {
return response.text();
}).then(function (data) {
data = JSON.parse(data);
logger.debug("Open Library search result: " + data);
return data;
const parsedData = JSON.parse(data);
logger.debug("Open Library search result: " + parsedData);
return parsedData;
}).catch(function (error) {
logger.error(error);
});
Expand Down
63 changes: 51 additions & 12 deletions src/components/ContentViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PDP, currentProfile } from "@/utils/Common.ts";
import { updateBookStatusForOne, InsertIntoDB, changeRating, downloadBook, getFromDB } from "@/utils/Fetchers.ts";
import { updateBookStatusForOne, InsertIntoDB, changeRating, downloadBook, getFromDB, updateBookStatusForAll } from "@/utils/Fetchers.ts";
import { IBook } from "@/interfaces/IBook.ts";
import { providerEnum, resolveTitle, tryToParse } from "@/utils/utils.ts";
import { ArrowBack, ArrowForward, AutoStories, Check, Close, Done, Download, Edit, Favorite, OpenInNew, PlayArrow, QuestionMark, Refresh, YoutubeSearchedFor } from "@mui/icons-material";
Expand All @@ -20,6 +20,7 @@ import { GoogleBooks } from "@/API/GoogleBooks.ts";
import { Marvel } from "@/API/Marvel.ts";
import { OpenLibrary } from "@/API/OpenLibrary.ts";
import ContainerExplorer from "./ContainerExplorer.tsx";
import RematchDialog from "./Dialogs/RematchDialog.tsx";


//providerEnum to type
Expand Down Expand Up @@ -316,9 +317,18 @@ function ContentViewer({ provider, TheBook, type, handleAddBreadcrumbs, handleCh
const handleCloseDatabaseEditorDialog = () => {
setOpenDatabaseEditorDialog(false);
};

const [openRematchDialog, setOpenRematchDialog] = useState(false);
const handleCloseRematchDialog = () => {
setOpenRematchDialog(false);
};
const handleOpenRematchDialog = () => {
setOpenRematchDialog(true);
};
return (<>
<DatabaseEditorDialog openModal={openDatabaseEditorDialog} onClose={handleCloseDatabaseEditorDialog} TheBook={TheBook} type={'book'} />
<DatabaseEditorDialog openModal={openDatabaseEditorDialog} onClose={handleCloseDatabaseEditorDialog} TheBook={TheBook} type={type === "volume" ? "book" : "series"} />
<MoreInfoDialog openModal={openMoreInfo} onClose={() => { closeMoreInfo(); }} desc={moreInfoContent.desc} name={moreInfoContent.name} hrefURL={moreInfoContent.href} image={moreInfoContent.image} type={moreInfoContent.type} />
<RematchDialog openModal={openRematchDialog} onClose={handleCloseRematchDialog} provider={provider} type={type === "volume" ? "book" : "serie"} oldID={TheBook.ID_book} />
<div
style={
{
Expand Down Expand Up @@ -372,7 +382,7 @@ function ContentViewer({ provider, TheBook, type, handleAddBreadcrumbs, handleCh
(provider === providerEnum.Marvel) ?
<h1><a target='_blank' href={((TheBook.URLs == "null") ? ("#") : (tryToParse(TheBook.URLs)[0].url))} >{TheBook.NOM}<i style={{ fontSize: '18px', top: '-10px', position: 'relative' }} className='material-icons'>open_in_new</i></a></h1> :
(provider === providerEnum.Anilist) ?
<h1><a target='_blank' href={(TheBook.URLs == "null") ? ("#") : (TheBook.URLs)}>{TheBook.NOM}<OpenInNew /></a></h1> :
<h1><a target='_blank' href={(TheBook.URLs == "null") ? ("#") : tryToParse(TheBook.URLs)}>{TheBook.NOM}<OpenInNew /></a></h1> :
<h1><a target='_blank'>{TheBook.NOM}<OpenInNew /></a></h1>
}
<Grid2 container sx={
Expand Down Expand Up @@ -527,7 +537,11 @@ function ContentViewer({ provider, TheBook, type, handleAddBreadcrumbs, handleCh
<IconButton
onClick={
() => {
updateBookStatusForOne("read", TheBook.ID_book);
if (type == "volume") {
updateBookStatusForOne("read", TheBook.ID_book);
} else {
updateBookStatusForAll("read", TheBook.raw_title);
}
Toaster(t("mkread"), "success");
}
}
Expand All @@ -537,7 +551,11 @@ function ContentViewer({ provider, TheBook, type, handleAddBreadcrumbs, handleCh
<IconButton id="readingbtndetails" style={{ display: type === "series" ? "none" : "block" }}
onClick={
() => {
updateBookStatusForOne("reading", TheBook.ID_book);
if (type == "volume") {
updateBookStatusForOne("reading", TheBook.ID_book);
} else {
updateBookStatusForAll("reading", TheBook.raw_title);
}
Toaster(t("mkreading"), "success");
}
}
Expand All @@ -546,7 +564,11 @@ function ContentViewer({ provider, TheBook, type, handleAddBreadcrumbs, handleCh
<IconButton id="decheckbtn"
onClick={
() => {
updateBookStatusForOne("unread", TheBook.ID_book);
if (type == "volume") {
updateBookStatusForOne("unread", TheBook.ID_book);
} else {
updateBookStatusForAll("unread", TheBook.raw_title);
}
Toaster(t("mkunread"), "success");
}
}
Expand Down Expand Up @@ -679,21 +701,38 @@ function ContentViewer({ provider, TheBook, type, handleAddBreadcrumbs, handleCh
<IconButton id="refreshBtn"
onClick={
async () => {
if (provider === providerEnum.Anilist || provider === providerEnum.MANUAL) {
Toaster(t("providerCannotRematch"), "error");
if (type === "volume") {
if (provider === providerEnum.Anilist || provider === providerEnum.MANUAL) {
Toaster(t("providerCannotRematch"), "error");
} else {
if (TheBook.lock !== 1) {
await new API().refreshMeta(TheBook.ID_book, provider, type === "series" ? "series" : "book");
} else {
Toaster(type === "series" ? t("seriesLocked") : t("bookLocked"), "error");
}
}
} else {
if (TheBook.lock !== 1) {
await new API().refreshMeta(TheBook.ID_book, provider, type === "series" ? "series" : "book");
if (provider === providerEnum.MANUAL) {
Toaster(t("providerCannotRematch"), "error");
} else {
Toaster(type === "series" ? t("seriesLocked") : t("bookLocked"), "error");
if (TheBook.lock !== 1) {
await new API().refreshMeta(TheBook.ID_book, provider, type === "series" ? "series" : "book");
} else {
Toaster(type === "series" ? t("seriesLocked") : t("bookLocked"), "error");
}
}
}

}
}
> <Refresh /></IconButton>
</Tooltip>
<Tooltip title={t('rematch')}>
<IconButton id="rematchBtn"> <YoutubeSearchedFor /></IconButton>
<IconButton id="rematchBtn"
onClick={
() => handleOpenRematchDialog()
}
> <YoutubeSearchedFor /></IconButton>
</Tooltip>
</Grid2>
<div id="ratingContainer" className="rating">
Expand Down
48 changes: 36 additions & 12 deletions src/components/DatabaseEditorSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function DatabaseEditorSkeleton({ TheBook, type, triggerSend, tra

useLayoutEffect(() => {
if (TheBook) {
console.log(TheBook);
document.querySelectorAll("#commonEdit>div>div>input").forEach((e: any) => {
e.value = TheBook[e.id.replaceAll("edit_", "")];
});
Expand All @@ -33,6 +34,8 @@ export default function DatabaseEditorSkeleton({ TheBook, type, triggerSend, tra
});
} else if (type === 'book') {
document.querySelectorAll("#bookEdit>div>div>input").forEach((e: any) => {
console.log(e.id.replaceAll("edit_", ""), TheBook[e.id.replaceAll("edit_", "")]);

e.value = TheBook[e.id.replaceAll("edit_", "")];
});
}
Expand All @@ -43,21 +46,42 @@ export default function DatabaseEditorSkeleton({ TheBook, type, triggerSend, tra
const values = [];
const columns = [];
document.querySelectorAll("#commonEdit>div>div>input").forEach((e: any) => {
console.log(e.value);
values.push(e.value.replaceAll("'", "''").replaceAll('"', "'"));
values.push(e.value);
columns.push(e.id.replaceAll("edit_", ""));
});
if (type === 'series') {
document.querySelectorAll("#seriesEdit>div>div>input").forEach((e: any) => {
values.push(e.value.replaceAll("'", "''").replaceAll('"', "'"));
columns.push(e.id.replaceAll("edit_", ""));
values.push(e.value);
switch (e.id.replaceAll("edit_", "")) {
case "raw_title":
columns.push("title");
break;
case "URLCover":
columns.push("cover");
break;
case "URLs":
columns.push("source");
break;
case "BG_cover":
columns.push("BG");
break;
case "issueNumber":
columns.push("chapters");
break;
case "score":
columns.push("Score");
break;
default:
columns.push(e.id.replaceAll("edit_", ""));
}
});
} else if (type === 'book') {
document.querySelectorAll("#bookEdit>div>div>input").forEach((e: any) => {
values.push(e.value.replaceAll("'", "''").replaceAll('"', "'"));
values.push(e.value);
columns.push(e.id.replaceAll("edit_", ""));
});
}

const lockCheck = document.getElementById("lockCheck") as HTMLInputElement;
values.push(lockCheck ? lockCheck.checked : false);
columns.push("lock");
Expand Down Expand Up @@ -129,31 +153,31 @@ export default function DatabaseEditorSkeleton({ TheBook, type, triggerSend, tra
<TextField
required
margin="dense"
id="edit_title"
id="edit_raw_title"
label={'Title'}
type="text"
fullWidth
variant="outlined"
/><TextField
required
margin="dense"
id="edit_cover"
id="edit_URLCover"
label={'Cover'}
type="text"
fullWidth
variant="outlined"
/><TextField
required
margin="dense"
id="edit_SOURCE"
id="edit_URLs"
label={'Source'}
type="text"
fullWidth
variant="outlined"
/><TextField
required
margin="dense"
id="edit_BG"
id="edit_BG_cover"
label={'Link BG'}
type="text"
fullWidth
Expand Down Expand Up @@ -187,7 +211,7 @@ export default function DatabaseEditorSkeleton({ TheBook, type, triggerSend, tra
<TextField
required
margin="dense"
id="edit_Score"
id="edit_score"
label={'Score'}
type="text"
fullWidth
Expand All @@ -213,15 +237,15 @@ export default function DatabaseEditorSkeleton({ TheBook, type, triggerSend, tra
/> <TextField
required
margin="dense"
id="edit_TRENDING"
id="edit_trending"
label={'Trending'}
type="text"
fullWidth
variant="outlined"
/> <TextField
required
margin="dense"
id="edit_chapters"
id="edit_issueNumber"
label={'Chapters'}
type="text"
fullWidth
Expand Down
6 changes: 3 additions & 3 deletions src/components/Dialogs/APISelectorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ export default function APISelectorDialog({ onClose, openModal }: {
provider === providerEnum.MANUAL ?
<DatabaseEditorSkeleton TheBook={TheBook} type={"book"} triggerSend={send} trackedMode={true} />
: provider === providerEnum.Marvel ?
<RematchSkeleton provider={provider} type={"book"} />
<RematchSkeleton provider={provider} type={"book"} oldID={TheBook.ID_book} />
: provider === providerEnum.Anilist ?
<DatabaseEditorSkeleton TheBook={TheBook} type={"book"} triggerSend={send} trackedMode={true} />
: provider === providerEnum.GBooks ?
<RematchSkeleton TheBook={TheBook} type={"book"} />
<RematchSkeleton provider={provider} type={"book"} oldID={TheBook.ID_book} />
: provider === providerEnum.OL ?
<RematchSkeleton TheBook={TheBook} type={"book"} />
<RematchSkeleton provider={provider} type={"book"} oldID={TheBook.ID_book} />
: <p>
{t("error")}
</p> : <></>
Expand Down
7 changes: 6 additions & 1 deletion src/components/Dialogs/DatabaseEditorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export default function DatabaseEditorDialog({ onClose, openModal, TheBook, type
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>{t("cancel")}</Button>
<Button onClick={() => { setSend(true); }}>{t("send")}</Button>
<Button onClick={() => {
setSend(true);
setTimeout(() => {
handleClose();
}, 500);
}}>{t("send")}</Button>
</DialogActions>
</Dialog>
</div >
Expand Down
7 changes: 3 additions & 4 deletions src/components/Dialogs/RematchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import RematchSkeleton from '../RematchSkeleton';
* @param type - A string value to indicate the type of rematch ("book" or "serie").
* @returns A React component.
*/
export default function RematchDialog({ onClose, openModal, provider, type }: {
export default function RematchDialog({ onClose, openModal, provider, type, oldID }: {
onClose: any,
openModal: boolean,
provider: any,
type: "book" | "serie",
oldID: string;
}) {
const { t } = useTranslation();
const [open, setOpen] = React.useState(openModal);
Expand All @@ -45,9 +46,7 @@ export default function RematchDialog({ onClose, openModal, provider, type }: {
maxWidth="md">
<DialogTitle>{t("rematchTitle")}</DialogTitle>
<DialogContent>
<DialogContentText>
<RematchSkeleton provider={provider} type={type} />
</DialogContentText>
<RematchSkeleton provider={provider} type={type} oldID={oldID} />
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>{t("done")}</Button>
Expand Down
Loading

0 comments on commit c9538a6

Please sign in to comment.