feat: consolidate alt text in same useState
This commit is contained in:
parent
00991ad93c
commit
339cab776a
|
@ -10,8 +10,11 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
||||||
const discardLabel = "Discard";
|
const discardLabel = "Discard";
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [imageData, setImageData] = useState({ url: "", token: "" });
|
const [imageData, setImageData] = useState({
|
||||||
const [imageAlt, setImageAlt] = useState("No image");
|
url: "",
|
||||||
|
token: "",
|
||||||
|
alt: "No image",
|
||||||
|
});
|
||||||
|
|
||||||
function acceptAction() {
|
function acceptAction() {
|
||||||
fetch(`${backendUrl}/image/review`, {
|
fetch(`${backendUrl}/image/review`, {
|
||||||
|
@ -45,7 +48,7 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
||||||
|
|
||||||
const getNewImage = () => {
|
const getNewImage = () => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
setImageData({ url: "", token: "" });
|
setImageData({ url: "", token: "", alt: "Loading..." });
|
||||||
fetch(`${backendUrl}/image`, {
|
fetch(`${backendUrl}/image`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
})
|
})
|
||||||
|
@ -54,11 +57,10 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setImageData({ url: data.url, token: data.token });
|
setImageData({ url: data.url, token: data.token, alt: data.url });
|
||||||
setImageAlt(data.url);
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setImageAlt("Error");
|
setImageData({ url: "", token: "", alt: "Error" });
|
||||||
console.error(error);
|
console.error(error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
@ -84,7 +86,7 @@ export default function ImageModerator({ backendUrl }: ImageModeratorProps) {
|
||||||
) : (
|
) : (
|
||||||
<img
|
<img
|
||||||
src={imageData.url}
|
src={imageData.url}
|
||||||
alt={imageAlt}
|
alt={imageData.alt}
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
|
|
Loading…
Reference in New Issue