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