improve questions preview

This commit is contained in:
nflnkr 2023-10-13 15:10:14 +03:00
parent d8fca6a339
commit db8e8029d0
4 changed files with 49 additions and 36 deletions

@ -9,21 +9,21 @@ interface Props {
export default function File({ question }: Props) { export default function File({ question }: Props) {
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
const [files, setFiles] = useState<File[] | null>(null); const [file, setFile] = useState<File | null>(null);
function handleFileChange(event: ChangeEvent<HTMLInputElement>) { function handleFileChange(event: ChangeEvent<HTMLInputElement>) {
if (!event.target.files) return setFiles(null); if (!event.target.files?.[0]) return setFile(null);
setFiles(Array.from(event.target.files)); setFile(event.target.files[0]);
} }
return ( return (
<Box sx={{ <Box sx={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "start",
gap: 1, gap: 1,
}}> }}>
<Typography variant="h6">{question.title}</Typography> <Typography variant="h6">{question.title}</Typography>
<Box>
<Button <Button
variant="contained" variant="contained"
onClick={() => fileInputRef.current?.click()} onClick={() => fileInputRef.current?.click()}
@ -38,7 +38,7 @@ export default function File({ question }: Props) {
}} }}
/> />
</Button> </Button>
</Box> {file && <Typography>Выбран файл: {file.name}</Typography>}
</Box> </Box>
); );
} }

@ -53,6 +53,7 @@ export default function Images({ question }: Props) {
borderColor: selectedVariants.includes(index) ? theme.palette.brightPurple.main : "#E3E3E3", borderColor: selectedVariants.includes(index) ? theme.palette.brightPurple.main : "#E3E3E3",
}} }}
> >
{variant.extendedText ?
<img <img
src={variant.extendedText} src={variant.extendedText}
alt="question variant" alt="question variant"
@ -63,6 +64,9 @@ export default function Images({ question }: Props) {
flexGrow: 1, flexGrow: 1,
}} }}
/> />
:
<Typography p={2}>Картинка отсутствует</Typography>
}
<Divider sx={{ width: "100%" }} /> <Divider sx={{ width: "100%" }} />
<Box sx={{ <Box sx={{
display: "flex", display: "flex",

@ -12,12 +12,23 @@ export default function Page({ question }: Props) {
<Box sx={{ <Box sx={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "start",
gap: 1, gap: 1,
}}> }}>
<Typography variant="h6">{question.title}</Typography> <Typography variant="h6">{question.title}</Typography>
<Box>
<Typography>{question.content.text}</Typography> <Typography>{question.content.text}</Typography>
</Box> {question.content.picture &&
<img
src={question.content.picture}
alt=""
style={{
width: "100%",
display: "block",
objectFit: "scale-down",
flexGrow: 1,
}}
/>
}
</Box> </Box>
); );
} }

@ -55,8 +55,6 @@ export default function Varimg({ question }: Props) {
<Box sx={{ <Box sx={{
border: "1px solid #E3E3E3", border: "1px solid #E3E3E3",
maxWidth: "400px", maxWidth: "400px",
minWidth: "200px",
minHeight: "150px",
display: "flex", display: "flex",
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
@ -64,7 +62,7 @@ export default function Varimg({ question }: Props) {
}}> }}>
{currentVariant?.extendedText ? {currentVariant?.extendedText ?
<img <img
src={currentVariant?.extendedText} src={currentVariant.extendedText}
alt="question variant" alt="question variant"
style={{ style={{
width: "100%", width: "100%",
@ -74,7 +72,7 @@ export default function Varimg({ question }: Props) {
}} }}
/> />
: :
<Typography>Выберите вариант</Typography> <Typography p={2}>{selectedVariantIndex === -1 ? "Выберите вариант" : "Картинка отсутствует"}</Typography>
} }
</Box> </Box>
</Box> </Box>