varimg имеет кнопку удаления
This commit is contained in:
parent
18ae9887d4
commit
f5ed7517fa
@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Box, ButtonBase, RadioGroup, Typography, useTheme } from "@mui/material";
|
import { Box, ButtonBase, RadioGroup, Typography, useTheme, IconButton } from "@mui/material";
|
||||||
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
|
|
||||||
import { VarimgVariant } from "./VarimgVariant";
|
import { VarimgVariant } from "./VarimgVariant";
|
||||||
import { OwnVarimgImage } from "./OwnVarimgImage";
|
import { OwnVarimgImage } from "./OwnVarimgImage";
|
||||||
@ -76,6 +77,15 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRemoveImage = (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
if (ownVariantData) {
|
||||||
|
// Сохраняем текущий answer, очищаем только изображения
|
||||||
|
const currentAnswer = ownVariantData.variant.answer || "";
|
||||||
|
updateOwnVariant(ownVariantData.id, currentAnswer, "", "", "");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (moment.isMoment(answer)) throw new Error("Answer is Moment in Variant question");
|
if (moment.isMoment(answer)) throw new Error("Answer is Moment in Variant question");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -162,6 +172,7 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
backgroundColor: "#9A9AAF30",
|
backgroundColor: "#9A9AAF30",
|
||||||
color: theme.palette.text.primary,
|
color: theme.palette.text.primary,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
|
position: "relative",
|
||||||
"&:hover": {
|
"&:hover": {
|
||||||
backgroundColor: ownVariantInQuestion ? "rgba(0,0,0,0.04)" : "transparent",
|
backgroundColor: ownVariantInQuestion ? "rgba(0,0,0,0.04)" : "transparent",
|
||||||
},
|
},
|
||||||
@ -172,12 +183,34 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
const imageUrl = variant?.isOwn && ownImageUrl ? ownImageUrl : choiceImgUrlAnswer;
|
const imageUrl = variant?.isOwn && ownImageUrl ? ownImageUrl : choiceImgUrlAnswer;
|
||||||
if (imageUrl) {
|
if (imageUrl) {
|
||||||
return (
|
return (
|
||||||
<img
|
<>
|
||||||
key={imageUrl}
|
<img
|
||||||
src={imageUrl}
|
key={imageUrl}
|
||||||
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
src={imageUrl}
|
||||||
alt=""
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
||||||
/>
|
alt=""
|
||||||
|
/>
|
||||||
|
{variant?.isOwn && ownImageUrl && (
|
||||||
|
<IconButton
|
||||||
|
onClick={handleRemoveImage}
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
top: 8,
|
||||||
|
left: 8,
|
||||||
|
zIndex: 1,
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
||||||
|
color: "white",
|
||||||
|
height: "25px",
|
||||||
|
width: "25px",
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CloseIcon />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return <BlankImage />;
|
return <BlankImage />;
|
||||||
|
Loading…
Reference in New Issue
Block a user