From 7ca7e249a219f3646320db2e8207c9ea497bf4c4 Mon Sep 17 00:00:00 2001 From: Sugui Date: Tue, 5 Mar 2024 17:00:09 +0100 Subject: [PATCH] Refactored ImageModerator --- bun.lockb | Bin 113083 -> 113083 bytes .../ImageModerator/ImageModerator.tsx | 16 ++++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bun.lockb b/bun.lockb index f55fb2bbf280f040af077e76fb2e12b37ae2e8e3..82f8b1397c679b963e5cda40b9d07fa6a2e15771 100755 GIT binary patch delta 26 icmdn}nQixHwuUW?KlL~m;|z`U%=C=5GwL($>H+|hya|8+ delta 26 dcmdn}nQixHwuUW?KlM167$9Ifqdw!VE&zlF2m1g3 diff --git a/src/components/ImageModerator/ImageModerator.tsx b/src/components/ImageModerator/ImageModerator.tsx index f82d4b1..ecf40ea 100644 --- a/src/components/ImageModerator/ImageModerator.tsx +++ b/src/components/ImageModerator/ImageModerator.tsx @@ -9,14 +9,17 @@ export interface ImageModeratorProps { export default function ImageModerator({ acceptLabel, discardLabel }: ImageModeratorProps) { const endpoint = "https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=1&json=1"; - const [loading, setLoading] = useState(true); + const [isLoading, setIsLoading] = useState(true); const [imageSrc, setImageSrc] = useState(""); const [imageAlt, setImageAlt] = useState("No image"); const getNewImage = () => { setImageSrc(""); - setLoading(true); - fetch(endpoint) + setIsLoading(true); + fetch(endpoint, { + method: "GET", + mode: "no-cors", + }) .then(response => { if (!response.ok) throw new Error("Response was not ok"); return response.json(); @@ -26,10 +29,11 @@ export default function ImageModerator({ acceptLabel, discardLabel }: ImageModer setImageSrc(imageUrl); setImageAlt(imageUrl); }) - .catch(_ => { + .catch(error => { setImageAlt("Error"); + console.error(error); }).finally(() => { - setLoading(false); + setIsLoading(false); }); } @@ -39,7 +43,7 @@ export default function ImageModerator({ acceptLabel, discardLabel }: ImageModer display: "grid", gridTemplateColumns: "1fr 1fr", gridTemplateRows: "1fr 50px", gridTemplateAreas: "'. .' '. .'", width: "100vw", height: "100vh" }}> - {loading ? Loading... : + {isLoading ? Loading... : {imageAlt}}