инпут принимает текст, ползунок с дебаунсером, qid берётся из урла на проде
This commit is contained in:
parent
25062ad07c
commit
4482aabda1
@ -20,9 +20,9 @@ export function sendAnswer({ questionId, body, qid }: any) {
|
||||
const answers = [{
|
||||
question_id: questionId,
|
||||
content: body, //тут массив с ответом
|
||||
qid
|
||||
}]
|
||||
formData.append("answers", JSON.stringify(answers));
|
||||
formData.append("qid", qid);
|
||||
|
||||
return makeRequest<FormData, { [key: string]: string; }>({
|
||||
url: `https://squiz.pena.digital/answer/answer`,
|
||||
@ -38,13 +38,13 @@ export function sendFile({ questionId, body, qid }: any) {
|
||||
const fd: any = {
|
||||
question_id: questionId,
|
||||
content: body.name,
|
||||
qid
|
||||
}
|
||||
|
||||
fd[body.name] = body.filen //target.files[0]
|
||||
|
||||
const answers = [fd]
|
||||
formData.append("answers", JSON.stringify(answers));
|
||||
formData.append("qid", qid);
|
||||
|
||||
return makeRequest<FormData, { [key: string]: string; }>({
|
||||
url: `https://squiz.pena.digital/answer/answer`,
|
||||
@ -89,6 +89,7 @@ export function sendFC({ questionId, body, qid }: any) {
|
||||
}]
|
||||
|
||||
formData.append("answers", JSON.stringify(answers));
|
||||
formData.append("qid", qid);
|
||||
|
||||
return makeRequest<FormData, { [key: string]: string; }>({
|
||||
url: `https://squiz.pena.digital/answer/answer`,
|
||||
|
@ -11,6 +11,14 @@ import { getData } from "@api/quizRelase"
|
||||
import type { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||
import { useGetSettings } from "../../utils/hooks/useGetSettings";
|
||||
|
||||
|
||||
const QID =
|
||||
process.env.NODE_ENV === "production" ?
|
||||
window.location.pathname
|
||||
:
|
||||
"c1ee11d2-ed5a-47d1-b500-bda6fd442114"
|
||||
|
||||
|
||||
export const ViewPage = () => {
|
||||
const { settings, cnt, items } = useQuestionsStore()
|
||||
|
||||
@ -20,12 +28,13 @@ export const ViewPage = () => {
|
||||
useEffect(() => {
|
||||
async function get() {
|
||||
try {
|
||||
const data = await getData("c1ee11d2-ed5a-47d1-b500-bda6fd442114")
|
||||
const data = await getData(QID)
|
||||
//@ts-ignore
|
||||
const settings = data.settings
|
||||
console.log(data)
|
||||
const parseData = {
|
||||
settings: {
|
||||
qid: "c1ee11d2-ed5a-47d1-b500-bda6fd442114",
|
||||
fp: settings.fp,
|
||||
rep: settings.rep,
|
||||
name: settings.name,
|
||||
|
@ -108,27 +108,13 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
max={max}
|
||||
step={currentQuestion.content.step || 1}
|
||||
onChange={async (_, value) => {
|
||||
|
||||
|
||||
const range = String(value).replace(",", "—");
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: range,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, range);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
updateAnswer(currentQuestion.id, range);
|
||||
updateMinRangeDebounced(range, true);
|
||||
|
||||
}}
|
||||
onChangeCommitted={(_, value) => {
|
||||
@ -146,40 +132,11 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
placeholder="0"
|
||||
value={answer}
|
||||
onChange={async({ target }) => {
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: window.Number(target.value) > max
|
||||
? String(max)
|
||||
: window.Number(target.value) < min
|
||||
? String(min)
|
||||
: target.value,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
window.Number(target.value) > max
|
||||
? String(max)
|
||||
: window.Number(target.value) < min
|
||||
? String(min)
|
||||
: target.value
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
updateMinRangeDebounced(window.Number(target.value) > max
|
||||
? String(max)
|
||||
: window.Number(target.value) < min
|
||||
? String(min)
|
||||
: target.value, true);
|
||||
}}
|
||||
sx={{
|
||||
maxWidth: "80px",
|
||||
|
@ -8,6 +8,7 @@ import type { QuizQuestionText } from "../../../model/questionTypes/text";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useDebouncedCallback } from "use-debounce";
|
||||
|
||||
type TextProps = {
|
||||
currentQuestion: QuizQuestionText;
|
||||
@ -18,6 +19,22 @@ export const Text = ({ currentQuestion }: TextProps) => {
|
||||
const { answers } = useQuizViewStore();
|
||||
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
||||
|
||||
const inputHC = useDebouncedCallback(async (text) => {
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: text,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
}, 400);
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h5">{currentQuestion.title}</Typography>
|
||||
@ -34,21 +51,8 @@ export const Text = ({ currentQuestion }: TextProps) => {
|
||||
//@ts-ignore
|
||||
value={answer || ""}
|
||||
onChange={async ({ target }) => {
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: target.value,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, target.value)
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
updateAnswer(currentQuestion.id, target.value)
|
||||
inputHC(target.value)
|
||||
}
|
||||
}
|
||||
/>
|
||||
|
@ -129,6 +129,7 @@ const VariantItem = ({
|
||||
index,
|
||||
own = false,
|
||||
}: VariantItemProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
@ -170,6 +171,7 @@ const VariantItem = ({
|
||||
if (currentQuestion.content.multi) {
|
||||
const currentAnswer = typeof answer !== "string" ? answer || [] : [];
|
||||
|
||||
console.log(settings)
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
|
Loading…
Reference in New Issue
Block a user