From 1bceeeb2f615ebc52066121a5f5234096bd0c06b Mon Sep 17 00:00:00 2001 From: Gabe Farrell Date: Mon, 24 Nov 2025 23:57:52 -0500 Subject: [PATCH] fix: add message to suggest dnd local file --- .../components/modals/ImageReplaceModal.tsx | 179 ++++++++++-------- 1 file changed, 102 insertions(+), 77 deletions(-) diff --git a/client/app/components/modals/ImageReplaceModal.tsx b/client/app/components/modals/ImageReplaceModal.tsx index d76dd61..53954f5 100644 --- a/client/app/components/modals/ImageReplaceModal.tsx +++ b/client/app/components/modals/ImageReplaceModal.tsx @@ -5,86 +5,111 @@ import SearchResults from "../SearchResults"; import { AsyncButton } from "../AsyncButton"; interface Props { - type: string - id: number - musicbrainzId?: string - open: boolean - setOpen: Function + type: string; + id: number; + musicbrainzId?: string; + open: boolean; + setOpen: Function; } -export default function ImageReplaceModal({ musicbrainzId, type, id, open, setOpen }: Props) { - const [query, setQuery] = useState(''); - const [loading, setLoading] = useState(false) - const [suggestedImgLoading, setSuggestedImgLoading] = useState(true) +export default function ImageReplaceModal({ + musicbrainzId, + type, + id, + open, + setOpen, +}: Props) { + const [query, setQuery] = useState(""); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(""); + const [suggestedImgLoading, setSuggestedImgLoading] = useState(true); - const doImageReplace = (url: string) => { - setLoading(true) - const formData = new FormData - formData.set(`${type.toLowerCase()}_id`, id.toString()) - formData.set("image_url", url) - replaceImage(formData) - .then((r) => { - if (r.ok) { - window.location.reload() - } else { - console.log(r) - setLoading(false) - } - }) - .catch((err) => console.log(err)) - } + const doImageReplace = (url: string) => { + setLoading(true); + setError(""); + const formData = new FormData(); + formData.set(`${type.toLowerCase()}_id`, id.toString()); + formData.set("image_url", url); + replaceImage(formData) + .then((r) => { + if (r.status >= 200 && r.status < 300) { + window.location.reload(); + } else { + r.json().then((r) => setError(r.error)); + setLoading(false); + } + }) + .catch((err) => setError(err)); + }; - const closeModal = () => { - setOpen(false) - setQuery('') - } + const closeModal = () => { + setOpen(false); + setQuery(""); + setError(""); + }; - return ( - -

Replace Image

-
- setQuery(e.target.value)} + return ( + +

Replace Image

+
+ setQuery(e.target.value)} + /> + {query != "" ? ( +
+ doImageReplace(query)} + > + Submit + +
+ ) : ( + "" + )} + {type === "Album" && musicbrainzId ? ( + <> +

Suggested Image (Click to Apply)

+ - - : '' - } -
-
- ) -} \ No newline at end of file +
+ + + ) : ( + "" + )} +

{error}

+ +
+ ); +}