aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-28 13:36:29 +0700
committerFactiven <[email protected]>2023-04-28 13:36:29 +0700
commitf287e8225892266acf162ba94ee31ce623e06890 (patch)
treeaca5e4626c78e7d92228f826f9ba4f26397f1559 /components
parentMerge pull request #3 from DevanAbinaya/main (diff)
downloadmoopa-f287e8225892266acf162ba94ee31ce623e06890.tar.xz
moopa-f287e8225892266acf162ba94ee31ce623e06890.zip
Editor List v0.2
Diffstat (limited to 'components')
-rw-r--r--components/listEditor.js15
-rw-r--r--components/useAlert.js6
2 files changed, 14 insertions, 7 deletions
diff --git a/components/listEditor.js b/components/listEditor.js
index f9e8ab8..d90e481 100644
--- a/components/listEditor.js
+++ b/components/listEditor.js
@@ -9,6 +9,7 @@ const ListEditor = ({ animeId, session, stats, prg, max }) => {
const handleSubmit = async (e) => {
e.preventDefault();
+ console.log("Submitting", status, progress);
try {
const response = await fetch("https://graphql.anilist.co/", {
method: "POST",
@@ -29,12 +30,16 @@ const ListEditor = ({ animeId, session, stats, prg, max }) => {
`,
variables: {
mediaId: animeId,
- progress: progress ? parseInt(progress) : null,
+ progress: progress,
status: status || null,
},
}),
});
const { data } = await response.json();
+ if (data.SaveMediaListEntry === null) {
+ showAlert("Something went wrong", "error");
+ return;
+ }
console.log("Saved media list entry", data);
// success();
showAlert("Media list entry saved", "success");
@@ -45,7 +50,7 @@ const ListEditor = ({ animeId, session, stats, prg, max }) => {
};
return (
- <div className="relative">
+ <div className="relative bg-secondary">
{message && (
<m.div
initial={{ opacity: 0, y: 10 }}
@@ -71,7 +76,7 @@ const ListEditor = ({ animeId, session, stats, prg, max }) => {
id="status"
value={status}
onChange={(e) => setStatus(e.target.value)}
- className="rounded-md px-2 py-1"
+ className="rounded-md px-2 py-1 bg-[#363642]"
>
<option value="">Select a status</option>
<option value="CURRENT">Watching</option>
@@ -92,13 +97,13 @@ const ListEditor = ({ animeId, session, stats, prg, max }) => {
value={progress}
max={max}
onChange={(e) => setProgress(e.target.value)}
- className="rounded-md px-2 py-1"
+ className="rounded-md px-2 py-1 bg-[#363642]"
min="0"
/>
</div>
<button
type="submit"
- className="bg-[#3a3a3a] text-white rounded-md mt-2 py-1 px-4"
+ className="bg-[#363642] text-white rounded-md mt-2 py-1 px-4"
>
Save
</button>
diff --git a/components/useAlert.js b/components/useAlert.js
index 7426096..fa82c42 100644
--- a/components/useAlert.js
+++ b/components/useAlert.js
@@ -10,8 +10,10 @@ const useAlert = () => {
setTimeout(() => {
setMessage("");
setType("");
- window.location.reload();
- }, 5000);
+ if (type === "success") {
+ window.location.reload();
+ }
+ }, 3000);
};
return { message, type, showAlert };