upgrade squzanswerer to 1.0.4
fetch and transform data for QuizAnswerer
This commit is contained in:
parent
06d8ce02d8
commit
d6a029c6c0
@ -7,7 +7,7 @@
|
|||||||
"@emotion/react": "^11.10.5",
|
"@emotion/react": "^11.10.5",
|
||||||
"@emotion/styled": "^11.10.5",
|
"@emotion/styled": "^11.10.5",
|
||||||
"@frontend/kitui": "^1.0.63",
|
"@frontend/kitui": "^1.0.63",
|
||||||
"@frontend/squzanswerer": "^1.0.1",
|
"@frontend/squzanswerer": "^1.0.4",
|
||||||
"@mui/icons-material": "^5.10.14",
|
"@mui/icons-material": "^5.10.14",
|
||||||
"@mui/material": "^5.10.14",
|
"@mui/material": "^5.10.14",
|
||||||
"@mui/x-date-pickers": "^6.16.1",
|
"@mui/x-date-pickers": "^6.16.1",
|
||||||
|
@ -61,6 +61,7 @@ export interface QuizQuestionBase {
|
|||||||
openedModalSettings: boolean;
|
openedModalSettings: boolean;
|
||||||
deleted: boolean;
|
deleted: boolean;
|
||||||
deleteTimeoutId: number;
|
deleteTimeoutId: number;
|
||||||
|
required: boolean;
|
||||||
content: {
|
content: {
|
||||||
id: string;
|
id: string;
|
||||||
hint: QuestionHint;
|
hint: QuestionHint;
|
||||||
|
@ -1,19 +1,81 @@
|
|||||||
import { QuizView } from "@frontend/squzanswerer";
|
import { questionApi } from "@api/question";
|
||||||
|
import { devlog } from "@frontend/kitui";
|
||||||
|
import { QuizAnswerer } from "@frontend/squzanswerer";
|
||||||
|
import { rawQuestionToQuestion } from "@model/question/question";
|
||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
|
import { useQuizes } from "@root/quizes/hooks";
|
||||||
|
import { isAxiosError } from "axios";
|
||||||
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
import useSWR from "swr";
|
||||||
|
|
||||||
export default function ViewPublicationPage() {
|
export default function ViewPublicationPage() {
|
||||||
const quizId = useParams().quizId;
|
const quizId = useParams().quizId;
|
||||||
|
const {
|
||||||
|
quizes,
|
||||||
|
error: quizesError,
|
||||||
|
isLoading: quizesIsLoading,
|
||||||
|
} = useQuizes();
|
||||||
|
|
||||||
if (!quizId) return null;
|
if (!quizId) return null;
|
||||||
|
|
||||||
|
const quiz = quizes?.find((quiz) => quiz.qid === quizId);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: rawQuestions,
|
||||||
|
isLoading: questionsIsLoading,
|
||||||
|
error: questionsError,
|
||||||
|
} = useSWR(
|
||||||
|
["questions", quiz?.backendId],
|
||||||
|
([, id]) => questionApi.getList({ quiz_id: id }),
|
||||||
|
{
|
||||||
|
onError: (error) => {
|
||||||
|
const message = isAxiosError<string>(error)
|
||||||
|
? error.response?.data ?? ""
|
||||||
|
: "";
|
||||||
|
|
||||||
|
devlog("Error getting question list", error);
|
||||||
|
enqueueSnackbar(`Не удалось получить вопросы. ${message}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (quizesError) {
|
||||||
|
console.log(`Error fetching quiz ${quizId}`, quizesError);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!quizes || quizesIsLoading) return null;
|
||||||
|
if (!rawQuestions || questionsIsLoading) return null;
|
||||||
|
|
||||||
|
if (!quiz) throw new Error("Quiz not found");
|
||||||
|
if (!rawQuestions) throw new Error("Questions not found");
|
||||||
|
|
||||||
|
const questions = rawQuestions.map(rawQuestionToQuestion);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
height: "100dvh",
|
height: "100dvh",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<QuizView quizId={quizId} />
|
<QuizAnswerer
|
||||||
|
quizSettings={{
|
||||||
|
cnt: rawQuestions?.length,
|
||||||
|
questions,
|
||||||
|
recentlyCompleted: false,
|
||||||
|
settings: {
|
||||||
|
fp: quiz.fingerprinting,
|
||||||
|
delay: 0,
|
||||||
|
due: quiz.due_to,
|
||||||
|
lim: quiz.limit,
|
||||||
|
name: quiz.name,
|
||||||
|
pausable: quiz.pausable,
|
||||||
|
rep: quiz.repeatable,
|
||||||
|
cfg: quiz.config,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
quizId={quizId}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
15
yarn.lock
15
yarn.lock
@ -1415,10 +1415,12 @@
|
|||||||
immer "^10.0.2"
|
immer "^10.0.2"
|
||||||
reconnecting-eventsource "^1.6.2"
|
reconnecting-eventsource "^1.6.2"
|
||||||
|
|
||||||
"@frontend/squzanswerer@^1.0.1":
|
"@frontend/squzanswerer@^1.0.4":
|
||||||
version "1.0.1"
|
version "1.0.4"
|
||||||
resolved "https://penahub.gitlab.yandexcloud.net/api/v4/projects/43/packages/npm/@frontend/squzanswerer/-/@frontend/squzanswerer-1.0.1.tgz#c266ae5402f0d9f2a288fa78ffa50201fa92ad94"
|
resolved "https://penahub.gitlab.yandexcloud.net/api/v4/projects/43/packages/npm/@frontend/squzanswerer/-/@frontend/squzanswerer-1.0.4.tgz#f16e26a2a22a1d1dbb83cb20132e39f0c4e006d8"
|
||||||
integrity sha1-wmauVALw2fKiiPp4/6UCAfqSrZQ=
|
integrity sha1-8W4moqIqHR27g8sgEy458MTgBtg=
|
||||||
|
dependencies:
|
||||||
|
country-flag-emoji-polyfill "^0.1.8"
|
||||||
|
|
||||||
"@humanwhocodes/config-array@^0.11.6":
|
"@humanwhocodes/config-array@^0.11.6":
|
||||||
version "0.11.7"
|
version "0.11.7"
|
||||||
@ -3958,6 +3960,11 @@ cosmiconfig@^7, cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
|
|||||||
path-type "^4.0.0"
|
path-type "^4.0.0"
|
||||||
yaml "^1.10.0"
|
yaml "^1.10.0"
|
||||||
|
|
||||||
|
country-flag-emoji-polyfill@^0.1.8:
|
||||||
|
version "0.1.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/country-flag-emoji-polyfill/-/country-flag-emoji-polyfill-0.1.8.tgz#d2cfb23dd2f949b80d83eb9822b613bf62957173"
|
||||||
|
integrity sha512-Mbah52sADS3gshUYhK5142gtUuJpHYOXlXtLFI3Ly4RqgkmPMvhX9kMZSTqDM8P7UqtSW99eHKFphhQSGXA3Cg==
|
||||||
|
|
||||||
craco-alias@^3.0.1:
|
craco-alias@^3.0.1:
|
||||||
version "3.0.1"
|
version "3.0.1"
|
||||||
resolved "https://registry.npmjs.org/craco-alias/-/craco-alias-3.0.1.tgz"
|
resolved "https://registry.npmjs.org/craco-alias/-/craco-alias-3.0.1.tgz"
|
||||||
|
Loading…
Reference in New Issue
Block a user