Skip to content

Commit

Permalink
refactor(Collectionner): ♻️ Merging the bookmarks and width changes o…
Browse files Browse the repository at this point in the history
…n the dialogs
  • Loading branch information
Nytuo committed Aug 31, 2023
1 parent 0f8109d commit 7cd169a
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 81 deletions.
3 changes: 2 additions & 1 deletion src/components/Dialogs/APISelectorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function APISelectorDialog({ onClose, openModal }: {

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("EDIT")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
9 changes: 7 additions & 2 deletions src/components/Dialogs/AboutDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ export default function AboutDialog({ onClose, openModal }: {

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("about")}</DialogTitle>
<DialogContent>
<DialogContentText>
<DialogContentText sx={
{
textAlign: "center",
}
}>
<h1 style={{ textAlign: "center" }}>Cosmic Comics</h1>
<img src="Images/Logo.png" alt="" width="auto" height="80px"
className="navbar-brand rotate linear infinite" /><img src="Images/LogoTxt.png" alt=""
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialogs/AddingLibraryDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function AddingLibraryDialog({ onClose, openModal }: {

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("EDIT")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
79 changes: 64 additions & 15 deletions src/components/Dialogs/BookmarksDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import { useEffect } from "react";
import { useTranslation } from 'react-i18next';
import { PDP, currentProfile } from '@/utils/Common.ts';
import { IconButton } from '@mui/material';
import { getFromDB } from '@/utils/Fetchers.ts';
import { openBOOKM } from '@/utils/utils.ts';
import { Block } from '@mui/icons-material';

export default function BookmarksDialog({ onClose, openModal }: {
onClose: any,
Expand All @@ -24,30 +29,74 @@ export default function BookmarksDialog({ onClose, openModal }: {
setOpen(false);
onClose();
};
const [bookmarks, setBookmarks] = React.useState<any[]>([]);
const listBM = async () => {
const option = {
method: 'GET', headers: {
'Content-Type': 'application/json', "token": currentProfile.getToken,
}
};
fetch(PDP + "/BM/getBM", option).then((response) => {
return response.json();
}).then(function (info) {
info.forEach((file: any) => {
getFromDB("Books", "URLCover FROM Books WHERE ID_BOOK = '" + file["BOOK_ID"] + "'").then(async (resa: any) => {
console.log(resa);
setBookmarks(bookmarks => [...bookmarks, {
URLCover: resa[0].URLCover,
page: file["page"],
path: file["PATH"]
}]
);
});
});
}).catch(function (error) {
console.log(error);
});
};

React.useLayoutEffect(() => {
listBM();
}, []);

return (
<div>
<Dialog open={open} onClose={handleClose}>
<DialogTitle>{t("EDIT")}</DialogTitle>
<Dialog open={open} onClose={handleClose}
fullWidth={true}
maxWidth="md"
>
<DialogTitle>{t("Bookmark")}</DialogTitle>
<DialogContent>
<DialogContentText>
<div id="bookmarkContainer" style="text-align: center"></div>
<div id="bookmarkContainer" style={{ textAlign: "center" }}>
{
bookmarks.length > 0 ?
bookmarks.map((bookmark: any, index: number) => {
console.log(bookmark);
return (
<div key={index}>
<Button
onClick={() => {
openBOOKM(bookmark.path, bookmark.page);
}
}
>
{
t("Seethepage") + bookmark.page
}
</Button>
<img src={bookmark.URLCover} />
</div>
);
}) : <div><Block /></div>
}
</div>
</DialogContentText>
<TextField
autoFocus
margin="dense"
id="passwordLogin"
label={t("ThePassToWorLabel")}
type="password"
fullWidth
variant="standard"
/>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>{t("send")}</Button>
<Button onClick={ }>{t("cancel")}</Button>
<Button onClick={handleClose}>{t("cancel")}</Button>
</DialogActions>
</Dialog>
</div>
);
};
}
3 changes: 2 additions & 1 deletion src/components/Dialogs/CreateAccountDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default function CreateAccountDialog({ openModal, title, text, okBtn, cre
}, [openModal]);
return (
<div>
<Dialog open={open}>
<Dialog open={open} fullWidth={true}
maxWidth="md">
<DialogTitle>{title}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialogs/DatabaseEditorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default function DatabaseEditorDialog({ onClose, openModal, TheBook, type

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("EDIT")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialogs/DownloadDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function DownloadDialog({ onClose, openModal }: {

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("EDIT")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialogs/LoginDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default function LoginDialog({ onClose, openModal, title, text, okBtn, ca

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{title}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialogs/MoreInfoDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default function MoreInfoDialog({ onClose, openModal, desc, name, hrefURL

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("seeMore")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
27 changes: 23 additions & 4 deletions src/components/Dialogs/NavigationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useTranslation } from 'react-i18next';
import { Icon, IconButton, Tooltip } from '@mui/material';
import { Bookmark, Download, Info, PhotoLibrary, Settings, TipsAndUpdates } from '@mui/icons-material';
import AboutDialog from './AboutDialog';
import BookmarksDialog from './BookmarksDialog';

export default function NavigationDialog({ onClose, openModal }: {
onClose: any,
Expand All @@ -36,15 +37,32 @@ export default function NavigationDialog({ onClose, openModal }: {
setOpenAbout(false);
};

const [openBookmarks, setOpenBookmarks] = React.useState(false);
const handleOpenBookmarks = (event: React.MouseEvent<HTMLElement>) => {
setOpenBookmarks(true);
};

const handleCloseBookmarks = () => {
setOpenBookmarks(false);
};
return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("navigation")}</DialogTitle>
<DialogContent>
<DialogContentText>
<div id="controller">
<div id="controller"
style={
{
display: "flex",
justifyContent: "space-around",
alignItems: "center",
}
}
>
<Tooltip title={t('Bookmark')}>
<IconButton>
<IconButton onClick={handleOpenBookmarks}>
<Bookmark />
</IconButton>
</Tooltip>
Expand Down Expand Up @@ -88,6 +106,7 @@ export default function NavigationDialog({ onClose, openModal }: {
</DialogActions>
</Dialog>
<AboutDialog openModal={openAbout} onClose={handleCloseAbout} />
<BookmarksDialog openModal={openBookmarks} onClose={handleCloseBookmarks} />
</div>
);
};
}
3 changes: 2 additions & 1 deletion src/components/Dialogs/RematchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default function RematchDialog({ onClose, openModal, provider, type }: {

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("EDIT")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialogs/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function SettingsDialog({ onClose, openModal }: {

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("EDIT")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dialogs/UploadDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default function UploadDialog({ onClose, openModal, cosmicComicsTemp }: {

return (
<div>
<Dialog open={open} onClose={handleClose}>
<Dialog open={open} onClose={handleClose} fullWidth={true}
maxWidth="md">
<DialogTitle>{t("upload")}</DialogTitle>
<DialogContent>
<DialogContentText>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialogs/UserAccountDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function UserAccountDialog({ forWhat, onClose, openModal }: {
<div>
<Dialog open={open} onClose={handleClose}
maxWidth="md"
fullWidth
fullWidth={true}
>
<DialogTitle>{forWhat == 'edit' ? t("EDIT") : t("Createanewuser")}</DialogTitle>
<DialogContent>
Expand Down
49 changes: 0 additions & 49 deletions src/static/collectionner.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,6 @@ function resetLibModal() {
};
}

//List of Bookmarked folder
function listBM() {
const option = {
method: 'GET', headers: {
'Content-Type': 'application/json', "token": currentProfile.getToken,
}
};
fetch(PDP + "/BM/getBM", option).then((response) => {
return response.json();
}).then(function (info) {
console.log(info);
if (info.length === 0) {
let iblock = document.createElement("i");
iblock.innerText = "block";
iblock.className = "material-icons";
if (currenttheme > 1) iblock.style.color = theme_FG;
document.getElementById("bookmarkContainer").appendChild(iblock);
return;
}
info.forEach((file) => {
getFromDB("Books", "URLCover FROM Books WHERE ID_BOOK = '" + file["BOOK_ID"] + "'").then(async (resa) => {
resa = JSON.parse(resa)
let res = resa[0].URLCover;
const btn = document.createElement("button");
console.log("openBOOKM('" + file["PATH"] + "&page=" + file["page"] + "');");
btn.addEventListener("click", function () {
openBOOKM(file["PATH"], file["page"]);
});
btn.className = "btn pure-material-button-contained";
btn.style = "margin:5px";
btn.innerText = language["Seethepage"] + file["page"];
let image = document.createElement("img");
image.src = res;
image.style = "width:100%;height:100%;";
let div = document.createElement("div");
div.appendChild(image);
div.style.width = "30%";
div.appendChild(btn);
document.getElementById("bookmarkContainer").appendChild(div);
});
});
}).catch(function (error) {
console.log(error);
});
}

//the Bookmarked loading
listBM();

//Handle the drag and drop to open files in the app
document.addEventListener("drop", (event) => {
event.preventDefault();
Expand Down

0 comments on commit 7cd169a

Please sign in to comment.