2024-05-31 17:56:17 +00:00
|
|
|
import { useQuizSettings } from "@/contexts/QuizDataContext";
|
2024-04-11 14:11:43 +00:00
|
|
|
import { AnyTypedQuizQuestion } from "@/model/questionTypes/shared";
|
|
|
|
import { Box, FormControl, MenuItem, Select as MuiSelect, useTheme } from "@mui/material";
|
2025-04-20 15:16:22 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-04-11 14:11:43 +00:00
|
|
|
|
|
|
|
interface Props {
|
2024-05-31 16:41:18 +00:00
|
|
|
selectedQuestion: AnyTypedQuizQuestion;
|
|
|
|
setQuestion: (questionIdF: string) => void;
|
2024-04-11 14:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function QuestionSelect({ selectedQuestion, setQuestion }: Props) {
|
2024-05-31 16:41:18 +00:00
|
|
|
const theme = useTheme();
|
2024-05-31 17:56:17 +00:00
|
|
|
const { questions, preview } = useQuizSettings();
|
2025-04-20 15:16:22 +00:00
|
|
|
const { t } = useTranslation();
|
2024-04-11 14:11:43 +00:00
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
if (!preview) return null;
|
2024-04-11 14:11:43 +00:00
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
p: "20px",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "center",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<FormControl
|
|
|
|
fullWidth
|
|
|
|
size="small"
|
|
|
|
sx={{
|
|
|
|
maxWidth: "500px",
|
|
|
|
minWidth: "200px",
|
|
|
|
height: "48px",
|
|
|
|
}}
|
|
|
|
className="cancel"
|
|
|
|
>
|
|
|
|
<MuiSelect
|
|
|
|
id="category-select"
|
|
|
|
variant="outlined"
|
|
|
|
value={selectedQuestion.id}
|
2025-04-20 15:16:22 +00:00
|
|
|
placeholder={t("Question title")}
|
2024-05-31 16:41:18 +00:00
|
|
|
onChange={({ target }) => {
|
|
|
|
setQuestion(target.value);
|
|
|
|
}}
|
|
|
|
sx={{
|
|
|
|
height: "48px",
|
|
|
|
borderRadius: "8px",
|
|
|
|
"& .MuiOutlinedInput-notchedOutline": {
|
|
|
|
border: `1px solid ${theme.palette.primary.main} !important`,
|
|
|
|
},
|
|
|
|
"& .MuiSelect-icon": {
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
MenuProps={{
|
|
|
|
PaperProps: {
|
|
|
|
sx: {
|
|
|
|
mt: "8px",
|
|
|
|
p: "4px",
|
|
|
|
borderRadius: "8px",
|
|
|
|
border: "1px solid #EEE4FC",
|
|
|
|
boxShadow: "0px 8px 24px rgba(210, 208, 225, 0.4)",
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
MenuListProps: {
|
|
|
|
sx: {
|
|
|
|
py: 0,
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
gap: "8px",
|
|
|
|
"& .Mui-selected": {
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
inputProps={{
|
|
|
|
sx: {
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
display: "block",
|
|
|
|
px: "9px",
|
|
|
|
gap: "20px",
|
|
|
|
width: "87%",
|
|
|
|
overflow: "hidden",
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{questions
|
|
|
|
.filter((q) => q.type !== "result")
|
|
|
|
.map((question, index) => (
|
|
|
|
<MenuItem
|
|
|
|
key={question.id}
|
|
|
|
value={question.id}
|
2024-04-11 14:11:43 +00:00
|
|
|
sx={{
|
2024-05-31 16:41:18 +00:00
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: "20px",
|
|
|
|
p: "4px",
|
|
|
|
borderRadius: "5px",
|
|
|
|
color: "#9A9AAF",
|
|
|
|
wordBreak: "break-word",
|
|
|
|
whiteSpace: "normal",
|
2024-04-11 14:11:43 +00:00
|
|
|
}}
|
2024-05-31 16:41:18 +00:00
|
|
|
>
|
|
|
|
{`${index + 1}. ${question.title}`}
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</MuiSelect>
|
|
|
|
</FormControl>
|
|
|
|
</Box>
|
|
|
|
);
|
2024-04-11 14:11:43 +00:00
|
|
|
}
|