Merge branch 'dev' into 'staging'
Dev See merge request frontend/squzanswerer!99
This commit is contained in:
commit
2d668f01d7
@ -6,18 +6,33 @@ import device from "current-device";
|
|||||||
import type { AxiosError } from "axios";
|
import type { AxiosError } from "axios";
|
||||||
import { replaceSpacesToEmptyLines } from "../components/ViewPublicationPage/tools/replaceSpacesToEmptyLines";
|
import { replaceSpacesToEmptyLines } from "../components/ViewPublicationPage/tools/replaceSpacesToEmptyLines";
|
||||||
import { QuizSettings } from "@model/settingsData";
|
import { QuizSettings } from "@model/settingsData";
|
||||||
|
import * as Bowser from "bowser";
|
||||||
let SESSIONS = "";
|
let SESSIONS = "";
|
||||||
|
|
||||||
const domain = location.hostname === "hbpn.link" ? "" : "https://s.hbpn.link";
|
const domain = location.hostname === "hbpn.link" ? "" : "https://s.hbpn.link";
|
||||||
|
|
||||||
const md = new MobileDetect(window.navigator.userAgent);
|
const md = new MobileDetect(window.navigator.userAgent);
|
||||||
|
|
||||||
const userAgent = navigator.userAgent
|
const userAgent = navigator.userAgent
|
||||||
let OSDevice = md.os()
|
//операционная система
|
||||||
if (OSDevice === null) {OSDevice = userAgent}
|
let OSDevice:string | undefined
|
||||||
|
if (userAgent.toLowerCase().includes("linux")) {OSDevice = "Linux"}
|
||||||
|
if (userAgent.toLowerCase().includes("windows")) {OSDevice = "Windows"}
|
||||||
|
if (/iPad|iPhone|iPod/.test(userAgent)){OSDevice = "IOS"}
|
||||||
|
if (userAgent.toLowerCase().includes("macintosh")) {OSDevice = "Mac OS"}
|
||||||
|
if (OSDevice === undefined) {OSDevice = userAgent}
|
||||||
|
|
||||||
|
//браузер
|
||||||
|
let browserUser:string
|
||||||
|
if(Bowser.name === "Chrome") {
|
||||||
|
browserUser = "Chrome"
|
||||||
|
} else if(Bowser.name === "Firefox") {
|
||||||
|
browserUser = "Firefox"
|
||||||
|
}else if(Bowser.name === "Safari") {
|
||||||
|
browserUser = "Safari"
|
||||||
|
}else{browserUser = userAgent}
|
||||||
|
|
||||||
const DeviceType = device.type
|
const DeviceType = device.type
|
||||||
|
|
||||||
let Device = md.mobile()
|
let Device = md.mobile()
|
||||||
if (Device === null) {Device = userAgent}
|
if (Device === null) {Device = userAgent}
|
||||||
|
|
||||||
@ -30,7 +45,7 @@ export const publicationMakeRequest = ({ url, body }: any) => {
|
|||||||
"DeviceType" : DeviceType,
|
"DeviceType" : DeviceType,
|
||||||
"Device" : Device,
|
"Device" : Device,
|
||||||
"OS": OSDevice,
|
"OS": OSDevice,
|
||||||
"Browser" : userAgent
|
"Browser" : browserUser
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
@ -99,7 +114,8 @@ export async function getQuizData(quizId: string) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendAnswer({ questionId, body, qid }: any) {
|
export function sendAnswer({ questionId, body, qid, preview }: any) {
|
||||||
|
if (preview) return
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const answers = [
|
const answers = [
|
||||||
@ -120,7 +136,8 @@ export function sendAnswer({ questionId, body, qid }: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//body ={file, filename}
|
//body ={file, filename}
|
||||||
export function sendFile({ questionId, body, qid }: any) {
|
export function sendFile({ questionId, body, qid, preview }: any) {
|
||||||
|
if (preview) return
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const answers: any = [
|
const answers: any = [
|
||||||
@ -143,7 +160,8 @@ export function sendFile({ questionId, body, qid }: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//форма контактов
|
//форма контактов
|
||||||
export function sendFC({ questionId, body, qid }: any) {
|
export function sendFC({ questionId, body, qid, preview }: any) {
|
||||||
|
if (preview) return
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
// const keysBody = Object.keys(body)
|
// const keysBody = Object.keys(body)
|
||||||
|
|||||||
@ -13,19 +13,22 @@ import { ApologyPage } from "./ViewPublicationPage/ApologyPage";
|
|||||||
import ViewPublicationPage from "./ViewPublicationPage/ViewPublicationPage";
|
import ViewPublicationPage from "./ViewPublicationPage/ViewPublicationPage";
|
||||||
import { RootContainerWidthContext } from "@contexts/RootContainerWidthContext";
|
import { RootContainerWidthContext } from "@contexts/RootContainerWidthContext";
|
||||||
import { startTransition, useEffect, useLayoutEffect, useRef, useState } from "react";
|
import { startTransition, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||||
|
import { getQuizData } from "@/api/quizRelase";
|
||||||
|
import LoadingSkeleton from "@/ui_kit/LoadingSkeleton";
|
||||||
|
|
||||||
|
|
||||||
moment.locale("ru");
|
moment.locale("ru");
|
||||||
const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText;
|
const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
quizSettings: QuizSettings;
|
quizSettings?: QuizSettings | {};
|
||||||
quizId: string;
|
quizId: string;
|
||||||
preview?: boolean;
|
preview?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function QuizAnswerer({ quizSettings, quizId, preview = false }: Props) {
|
export default function QuizAnswerer({ quizSettings = {}, quizId, preview = false }: Props) {
|
||||||
const [rootContainerWidth, setRootContainerWidth] = useState<number>(() => window.innerWidth);
|
const [rootContainerWidth, setRootContainerWidth] = useState<number>(() => window.innerWidth);
|
||||||
|
const [quizData, setQuizData] = useState<QuizSettings | {}>(quizSettings);
|
||||||
const rootContainerRef = useRef<HTMLDivElement>(null);
|
const rootContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
@ -33,6 +36,10 @@ export default function QuizAnswerer({ quizSettings, quizId, preview = false }:
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (Object.values(quizSettings).length === 0) {
|
||||||
|
const data = (async()=>await getQuizData(quizId))()
|
||||||
|
setQuizData(data)
|
||||||
|
}
|
||||||
const handleWindowResize = () => {
|
const handleWindowResize = () => {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
if (rootContainerRef.current) setRootContainerWidth(rootContainerRef.current.clientWidth);
|
if (rootContainerRef.current) setRootContainerWidth(rootContainerRef.current.clientWidth);
|
||||||
@ -45,9 +52,10 @@ export default function QuizAnswerer({ quizSettings, quizId, preview = false }:
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
if (Object.values(quizData).length === 0) return <LoadingSkeleton />;
|
||||||
return (
|
return (
|
||||||
<RootContainerWidthContext.Provider value={rootContainerWidth}>
|
<RootContainerWidthContext.Provider value={rootContainerWidth}>
|
||||||
<QuizDataContext.Provider value={{ ...quizSettings, quizId, preview }}>
|
<QuizDataContext.Provider value={{ ...quizData, quizId, preview }}>
|
||||||
<LocalizationProvider dateAdapter={AdapterMoment} adapterLocale="ru" localeText={localeText}>
|
<LocalizationProvider dateAdapter={AdapterMoment} adapterLocale="ru" localeText={localeText}>
|
||||||
<ThemeProvider theme={lightTheme}>
|
<ThemeProvider theme={lightTheme}>
|
||||||
<SnackbarProvider
|
<SnackbarProvider
|
||||||
|
|||||||
@ -38,7 +38,7 @@ type Props = {
|
|||||||
|
|
||||||
export const ContactForm = ({currentQuestion, onShowResult}: Props) => {
|
export const ContactForm = ({currentQuestion, onShowResult}: Props) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const {settings, questions, quizId, show_badge} = useQuizData();
|
const {settings, questions, quizId, show_badge, preview} = useQuizData();
|
||||||
|
|
||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(false);
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
@ -68,7 +68,7 @@ export const ContactForm = ({currentQuestion, onShowResult}: Props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!resultQuestion) throw new Error("Result question not found");
|
if (!resultQuestion) throw new Error("Result question not found");
|
||||||
|
console.log("yfcnhjqrb", settings.cfg.resultInfo.showResultForm)
|
||||||
const inputHC = async () => {
|
const inputHC = async () => {
|
||||||
const FC = settings.cfg.formContact.fields || settings.cfg.formContact;
|
const FC = settings.cfg.formContact.fields || settings.cfg.formContact;
|
||||||
const body = {} as any;
|
const body = {} as any;
|
||||||
@ -84,6 +84,7 @@ export const ContactForm = ({currentQuestion, onShowResult}: Props) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: body,
|
body: body,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
||||||
@ -141,8 +142,10 @@ export const ContactForm = ({currentQuestion, onShowResult}: Props) => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
enqueueSnackbar("повторите попытку позже");
|
enqueueSnackbar("повторите попытку позже");
|
||||||
}
|
}
|
||||||
|
if(settings.cfg.resultInfo.showResultForm === "after"){
|
||||||
|
onShowResult();
|
||||||
|
}
|
||||||
|
|
||||||
onShowResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setFire(false);
|
setFire(false);
|
||||||
@ -322,7 +325,9 @@ export const ContactForm = ({currentQuestion, onShowResult}: Props) => {
|
|||||||
<Box
|
<Box
|
||||||
component={Link}
|
component={Link}
|
||||||
target={"_blank"}
|
target={"_blank"}
|
||||||
href={"https://quiz.pena.digital"}
|
href={
|
||||||
|
`https://${window.location.hostname.includes("s") ? "s" : ""}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`
|
||||||
|
}
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export const ResultForm = ({resultQuestion}: ResultFormProps) => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useRootContainerSize() < 650;
|
const isMobile = useRootContainerSize() < 650;
|
||||||
const isTablet = useRootContainerSize() < 1000;
|
const isTablet = useRootContainerSize() < 1000;
|
||||||
const {settings, show_badge} = useQuizData();
|
const {settings, show_badge, quizId} = useQuizData();
|
||||||
const spec = settings.cfg.spec
|
const spec = settings.cfg.spec
|
||||||
console.log(quizThemes[settings.cfg.theme].isLight)
|
console.log(quizThemes[settings.cfg.theme].isLight)
|
||||||
|
|
||||||
@ -190,7 +190,9 @@ export const ResultForm = ({resultQuestion}: ResultFormProps) => {
|
|||||||
<Box
|
<Box
|
||||||
component={Link}
|
component={Link}
|
||||||
target={"_blank"}
|
target={"_blank"}
|
||||||
href={"https://quiz.pena.digital"}
|
href={
|
||||||
|
`https://${window.location.hostname.includes("s") ? "s" : ""}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`
|
||||||
|
}
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import PenaLogo from "@icons/PenaLogo.png";
|
|||||||
|
|
||||||
export const StartPageViewPublication = () => {
|
export const StartPageViewPublication = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { settings, show_badge } = useQuizData();
|
const { settings, show_badge, quizId } = useQuizData();
|
||||||
const { isMobileDevice } = useUADevice();
|
const { isMobileDevice } = useUADevice();
|
||||||
const isMobile = useRootContainerSize() < 700;
|
const isMobile = useRootContainerSize() < 700;
|
||||||
const isTablet = useRootContainerSize() < 800;
|
const isTablet = useRootContainerSize() < 800;
|
||||||
@ -330,7 +330,9 @@ export const StartPageViewPublication = () => {
|
|||||||
<Box
|
<Box
|
||||||
component={Link}
|
component={Link}
|
||||||
target={"_blank"}
|
target={"_blank"}
|
||||||
href={"https://quiz.pena.digital"}
|
href={
|
||||||
|
`https://${window.location.hostname.includes("s") ? "s" : ""}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`
|
||||||
|
}
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import {Button, ThemeProvider, useTheme} from "@mui/material";
|
import { Button, ThemeProvider, useTheme } from "@mui/material";
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
import { useQuizViewStore } from "@stores/quizView";
|
||||||
import { useQuestionFlowControl } from "@utils/hooks/useQuestionFlowControl";
|
import { useQuestionFlowControl } from "@utils/hooks/useQuestionFlowControl";
|
||||||
import { useQuizData } from "@contexts/QuizDataContext";
|
import { useQuizData } from "@contexts/QuizDataContext";
|
||||||
@ -12,11 +12,12 @@ import { ResultForm } from "./ResultForm";
|
|||||||
import { StartPageViewPublication } from "./StartPageViewPublication";
|
import { StartPageViewPublication } from "./StartPageViewPublication";
|
||||||
import PrevButton from "./tools/PrevButton";
|
import PrevButton from "./tools/PrevButton";
|
||||||
import NextButton from "./tools/NextButton";
|
import NextButton from "./tools/NextButton";
|
||||||
import {enqueueSnackbar} from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { sendAnswer } from "@api/quizRelase";
|
import { sendAnswer } from "@api/quizRelase";
|
||||||
|
import LoadingSkeleton from "@/ui_kit/LoadingSkeleton";
|
||||||
|
|
||||||
export default function ViewPublicationPage() {
|
export default function ViewPublicationPage() {
|
||||||
const { settings, recentlyCompleted, quizId } = useQuizData();
|
const { settings, recentlyCompleted, quizId, preview } = useQuizData();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
let currentQuizStep = useQuizViewStore((state) => state.currentQuizStep);
|
let currentQuizStep = useQuizViewStore((state) => state.currentQuizStep);
|
||||||
const isMobileMini = useRootContainerSize() < 382;
|
const isMobileMini = useRootContainerSize() < 382;
|
||||||
@ -31,15 +32,18 @@ export default function ViewPublicationPage() {
|
|||||||
} = useQuestionFlowControl();
|
} = useQuestionFlowControl();
|
||||||
|
|
||||||
const isAnswer = answers.some(ans => ans.questionId === currentQuestion.id)
|
const isAnswer = answers.some(ans => ans.questionId === currentQuestion.id)
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
function setFaviconAndTitle() {
|
function setFaviconAndTitle() {
|
||||||
const link = document.querySelector('link[rel="icon"]');
|
if (settings.cfg !== undefined) {
|
||||||
if (link && settings.cfg.startpage.favIcon) {
|
const link = document.querySelector('link[rel="icon"]');
|
||||||
link.setAttribute("href", settings.cfg.startpage.favIcon);
|
if (link && settings.cfg.startpage.favIcon) {
|
||||||
|
link.setAttribute("href", settings.cfg.startpage.favIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.title = settings.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.title = settings.name;
|
|
||||||
},
|
},
|
||||||
[settings]
|
[settings]
|
||||||
);
|
);
|
||||||
@ -64,24 +68,25 @@ export default function ViewPublicationPage() {
|
|||||||
<Question
|
<Question
|
||||||
currentQuestion={currentQuestion}
|
currentQuestion={currentQuestion}
|
||||||
currentQuestionStepNumber={currentQuestionStepNumber}
|
currentQuestionStepNumber={currentQuestionStepNumber}
|
||||||
prevButton={ <PrevButton isPreviousButtonEnabled={isPreviousButtonEnabled} moveToPrevQuestion={moveToPrevQuestion}/>}
|
prevButton={<PrevButton isPreviousButtonEnabled={isPreviousButtonEnabled} moveToPrevQuestion={moveToPrevQuestion} />}
|
||||||
nextButton={
|
nextButton={
|
||||||
<NextButton
|
<NextButton
|
||||||
isNextButtonEnabled={isNextButtonEnabled}
|
isNextButtonEnabled={isNextButtonEnabled}
|
||||||
moveToNextQuestion={async () => {
|
moveToNextQuestion={async () => {
|
||||||
if (!isAnswer) {
|
if (!isAnswer) {
|
||||||
try {
|
try {
|
||||||
await sendAnswer({
|
await sendAnswer({
|
||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: "",
|
body: "",
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
});
|
preview
|
||||||
} catch (e) {
|
});
|
||||||
enqueueSnackbar("ответ не был засчитан");
|
} catch (e) {
|
||||||
}
|
enqueueSnackbar("ответ не был засчитан");
|
||||||
}
|
}
|
||||||
moveToNextQuestion()
|
}
|
||||||
}}
|
moveToNextQuestion()
|
||||||
|
}}
|
||||||
/>}
|
/>}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -19,7 +19,7 @@ type DateProps = {
|
|||||||
|
|
||||||
export const Date = ({ currentQuestion }: DateProps) => {
|
export const Date = ({ currentQuestion }: DateProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { settings, quizId } = useQuizData();
|
const { settings, quizId, preview } = useQuizData();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
const answer = answers.find(
|
const answer = answers.find(
|
||||||
({ questionId }) => questionId === currentQuestion.id
|
({ questionId }) => questionId === currentQuestion.id
|
||||||
@ -65,6 +65,7 @@ export const Date = ({ currentQuestion }: DateProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: moment(date).format("YYYY.MM.DD"),
|
body: moment(date).format("YYYY.MM.DD"),
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(currentQuestion.id, date, 0);
|
updateAnswer(currentQuestion.id, date, 0);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ type EmojiProps = {
|
|||||||
|
|
||||||
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { quizId, settings } = useQuizData();
|
const { quizId, settings, preview } = useQuizData();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
const { answer } =
|
const { answer } =
|
||||||
answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
||||||
@ -103,6 +103,7 @@ export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
|||||||
" " +
|
" " +
|
||||||
currentQuestion.content.variants[index].answer,
|
currentQuestion.content.variants[index].answer,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(
|
updateAnswer(
|
||||||
@ -121,6 +122,7 @@ export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: "",
|
body: "",
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
enqueueSnackbar("ответ не был засчитан");
|
enqueueSnackbar("ответ не был засчитан");
|
||||||
|
|||||||
@ -30,7 +30,7 @@ type FileProps = {
|
|||||||
export const File = ({ currentQuestion }: FileProps) => {
|
export const File = ({ currentQuestion }: FileProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
const { quizId } = useQuizData();
|
const { quizId, preview } = useQuizData();
|
||||||
const [modalWarningType, setModalWarningType] = useState<ModalWarningType>(null);
|
const [modalWarningType, setModalWarningType] = useState<ModalWarningType>(null);
|
||||||
const [isSending, setIsSending] = useState<boolean>(false);
|
const [isSending, setIsSending] = useState<boolean>(false);
|
||||||
const [isDropzoneHighlighted, setIsDropzoneHighlighted] = useState<boolean>(false);
|
const [isDropzoneHighlighted, setIsDropzoneHighlighted] = useState<boolean>(false);
|
||||||
@ -59,7 +59,8 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: {
|
body: {
|
||||||
file: file,
|
file: file,
|
||||||
name: file.name
|
name: file.name,
|
||||||
|
preview
|
||||||
},
|
},
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
});
|
});
|
||||||
@ -67,8 +68,9 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
|
|
||||||
await sendAnswer({
|
await sendAnswer({
|
||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: `https://storage.yandexcloud.net/squizanswer/${quizId}/${currentQuestion.id}/${data.data.fileIDMap[currentQuestion.id]}`,
|
body: `https://storage.yandexcloud.net/squizanswer/${quizId}/${currentQuestion.id}/${data!.data.fileIDMap[currentQuestion.id]}`,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(currentQuestion.id, `${file.name}|${URL.createObjectURL(file)}`, 0);
|
updateAnswer(currentQuestion.id, `${file.name}|${URL.createObjectURL(file)}`, 0);
|
||||||
@ -137,6 +139,7 @@ export const File = ({ currentQuestion }: FileProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: "",
|
body: "",
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(answer);
|
console.log(answer);
|
||||||
|
|||||||
@ -24,7 +24,7 @@ type ImagesProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Images = ({ currentQuestion }: ImagesProps) => {
|
export const Images = ({ currentQuestion }: ImagesProps) => {
|
||||||
const { quizId } = useQuizData();
|
const { quizId, preview } = useQuizData();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const answer = answers.find(
|
const answer = answers.find(
|
||||||
@ -96,6 +96,7 @@ export const Images = ({ currentQuestion }: ImagesProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: `${currentQuestion.content.variants[index].answer} <img style="width:100%; max-width:250px; max-height:250px" src="${currentQuestion.content.variants[index].extendedText}"/>`,
|
body: `${currentQuestion.content.variants[index].answer} <img style="width:100%; max-width:250px; max-height:250px" src="${currentQuestion.content.variants[index].extendedText}"/>`,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
updateAnswer(
|
updateAnswer(
|
||||||
currentQuestion.id,
|
currentQuestion.id,
|
||||||
@ -113,6 +114,7 @@ export const Images = ({ currentQuestion }: ImagesProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: "",
|
body: "",
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
enqueueSnackbar("ответ не был засчитан");
|
enqueueSnackbar("ответ не был засчитан");
|
||||||
|
|||||||
@ -22,7 +22,7 @@ type NumberProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Number = ({ currentQuestion }: NumberProps) => {
|
export const Number = ({ currentQuestion }: NumberProps) => {
|
||||||
const { settings, quizId } = useQuizData();
|
const { settings, quizId, preview } = useQuizData();
|
||||||
const [inputValue, setInputValue] = useState<string>("0");
|
const [inputValue, setInputValue] = useState<string>("0");
|
||||||
const [minRange, setMinRange] = useState<string>("0");
|
const [minRange, setMinRange] = useState<string>("0");
|
||||||
const [maxRange, setMaxRange] = useState<string>("100000000000");
|
const [maxRange, setMaxRange] = useState<string>("100000000000");
|
||||||
@ -53,6 +53,7 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: value,
|
body: value,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!noUpdate) {
|
if (!noUpdate) {
|
||||||
|
|||||||
@ -58,7 +58,7 @@ const buttonRatingForm = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const Rating = ({ currentQuestion }: RatingProps) => {
|
export const Rating = ({ currentQuestion }: RatingProps) => {
|
||||||
const { quizId } = useQuizData();
|
const { quizId, preview } = useQuizData();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useRootContainerSize() < 650;
|
const isMobile = useRootContainerSize() < 650;
|
||||||
@ -102,6 +102,7 @@ export const Rating = ({ currentQuestion }: RatingProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: String(value) + " из " + currentQuestion.content.steps,
|
body: String(value) + " из " + currentQuestion.content.steps,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(currentQuestion.id, String(value), 0);
|
updateAnswer(currentQuestion.id, String(value), 0);
|
||||||
|
|||||||
@ -17,7 +17,7 @@ type SelectProps = {
|
|||||||
|
|
||||||
export const Select = ({ currentQuestion }: SelectProps) => {
|
export const Select = ({ currentQuestion }: SelectProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { quizId, settings } = useQuizData();
|
const { quizId, settings, preview } = useQuizData();
|
||||||
const [isSending, setIsSending] = useState<boolean>(false);
|
const [isSending, setIsSending] = useState<boolean>(false);
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
const { answer } =
|
const { answer } =
|
||||||
@ -65,6 +65,7 @@ export const Select = ({ currentQuestion }: SelectProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: "",
|
body: "",
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
enqueueSnackbar("ответ не был засчитан");
|
enqueueSnackbar("ответ не был засчитан");
|
||||||
@ -79,6 +80,7 @@ export const Select = ({ currentQuestion }: SelectProps) => {
|
|||||||
currentQuestion.content.variants[Number(value)].answer
|
currentQuestion.content.variants[Number(value)].answer
|
||||||
),
|
),
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(currentQuestion.id, String(value), 0);
|
updateAnswer(currentQuestion.id, String(value), 0);
|
||||||
|
|||||||
@ -55,7 +55,7 @@ const Orientation = [
|
|||||||
|
|
||||||
export const Text = ({ currentQuestion, stepNumber }: TextProps) => {
|
export const Text = ({ currentQuestion, stepNumber }: TextProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { settings } = useQuizData();
|
const { settings, preview } = useQuizData();
|
||||||
const spec = settings.cfg.spec;
|
const spec = settings.cfg.spec;
|
||||||
const { quizId } = useQuizData();
|
const { quizId } = useQuizData();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
@ -71,6 +71,7 @@ export const Text = ({ currentQuestion, stepNumber }: TextProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: text,
|
body: text,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
enqueueSnackbar("ответ не был засчитан");
|
enqueueSnackbar("ответ не был засчитан");
|
||||||
|
|||||||
@ -161,7 +161,7 @@ const VariantItem = ({
|
|||||||
setIsSending: (a: boolean) => void;
|
setIsSending: (a: boolean) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { settings, quizId } = useQuizData();
|
const { settings, quizId, preview } = useQuizData();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
@ -244,6 +244,7 @@ const VariantItem = ({
|
|||||||
? currentAnswer?.filter((item) => item !== variantId)
|
? currentAnswer?.filter((item) => item !== variantId)
|
||||||
: [...currentAnswer, variantId],
|
: [...currentAnswer, variantId],
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(
|
updateAnswer(
|
||||||
@ -267,6 +268,7 @@ const VariantItem = ({
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: currentQuestion.content.variants[index].answer,
|
body: currentQuestion.content.variants[index].answer,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(
|
updateAnswer(
|
||||||
@ -287,6 +289,7 @@ const VariantItem = ({
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: "",
|
body: "",
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|||||||
@ -25,7 +25,7 @@ type VarimgProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
||||||
const { settings, quizId } = useQuizData();
|
const { settings, quizId, preview } = useQuizData();
|
||||||
const { answers } = useQuizViewStore();
|
const { answers } = useQuizViewStore();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useRootContainerSize() < 650;
|
const isMobile = useRootContainerSize() < 650;
|
||||||
@ -130,6 +130,7 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: `${currentQuestion.content.variants[index].answer} <img style="width:100%; max-width:250px; max-height:250px" src="${currentQuestion.content.variants[index].extendedText}"/>`,
|
body: `${currentQuestion.content.variants[index].answer} <img style="width:100%; max-width:250px; max-height:250px" src="${currentQuestion.content.variants[index].extendedText}"/>`,
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
|
|
||||||
updateAnswer(
|
updateAnswer(
|
||||||
@ -147,6 +148,7 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
|||||||
questionId: currentQuestion.id,
|
questionId: currentQuestion.id,
|
||||||
body: "",
|
body: "",
|
||||||
qid: quizId,
|
qid: quizId,
|
||||||
|
preview
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
enqueueSnackbar("ответ не был засчитан");
|
enqueueSnackbar("ответ не был засчитан");
|
||||||
|
|||||||
@ -1,13 +1,19 @@
|
|||||||
import { QuizSettings } from "@model/settingsData";
|
import { QuizSettings } from "@model/settingsData";
|
||||||
import { createContext, useContext } from "react";
|
import { createContext, useContext } from "react";
|
||||||
|
|
||||||
type QuizData = QuizSettings & { quizId: string; preview: boolean; };
|
type QuizSettingsFull = QuizSettings | {};
|
||||||
|
type QuizData = QuizSettingsFull & { quizId: string; preview: boolean; };
|
||||||
|
type QuizDataClean = QuizSettings & { quizId: string; preview: boolean; };
|
||||||
|
|
||||||
export const QuizDataContext = createContext<QuizData | null>(null);
|
export const QuizDataContext = createContext<QuizData | null>(null);
|
||||||
|
|
||||||
export const useQuizData = () => {
|
export const useQuizData = ():QuizDataClean => {
|
||||||
const quizData = useContext(QuizDataContext);
|
const quizData = useContext(QuizDataContext);
|
||||||
if (quizData === null) throw new Error("QuizData context is null");
|
if (
|
||||||
|
quizData === null ||
|
||||||
|
!("settings" in quizData) ||
|
||||||
|
!("recentlyCompleted" in quizData)
|
||||||
|
) throw new Error("QuizData context is null");
|
||||||
|
|
||||||
return quizData;
|
return quizData;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -85,6 +85,7 @@
|
|||||||
"zustand": "^4.3.8"
|
"zustand": "^4.3.8"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"bowser": "1.9.4",
|
||||||
"country-flag-emoji-polyfill": "^0.1.8",
|
"country-flag-emoji-polyfill": "^0.1.8",
|
||||||
"current-device": "^0.10.2",
|
"current-device": "^0.10.2",
|
||||||
"hex-rgb": "^5.0.0",
|
"hex-rgb": "^5.0.0",
|
||||||
|
|||||||
@ -1337,6 +1337,11 @@ bluebird@^3.7.2:
|
|||||||
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
|
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
|
||||||
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
|
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
|
||||||
|
|
||||||
|
bowser@1.9.4:
|
||||||
|
version "1.9.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/bowser/-/bowser-1.9.4.tgz#890c58a2813a9d3243704334fa81b96a5c150c9a"
|
||||||
|
integrity sha512-9IdMmj2KjigRq6oWhmwv1W36pDuA4STQZ8q6YO9um+x07xgYNCD3Oou+WP/3L1HNz7iqythGet3/p4wvc8AAwQ==
|
||||||
|
|
||||||
brace-expansion@^1.1.7:
|
brace-expansion@^1.1.7:
|
||||||
version "1.1.11"
|
version "1.1.11"
|
||||||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user