fix wrong types

This commit is contained in:
nflnkr 2023-10-13 15:09:05 +03:00
parent 4b6ae87e05
commit d8fca6a339
5 changed files with 15 additions and 9 deletions

@ -1,8 +1,8 @@
import type { QuizQuestionBase } from "../model/questionTypes/shared"; import type { QuizQuestionInitial } from "../model/questionTypes/shared";
export const QUIZ_QUESTION_BASE: Omit<QuizQuestionBase, "id"> = { export const QUIZ_QUESTION_BASE: Omit<QuizQuestionInitial, "id"> = {
title: "", title: "",
type: "", type: "nonselected",
expanded: false, expanded: false,
required: false, required: false,
deleted: false, deleted: false,

@ -54,6 +54,10 @@ export interface QuizQuestionBase {
}; };
} }
export interface QuizQuestionInitial extends QuizQuestionBase {
type: "nonselected";
}
export type AnyQuizQuestion = export type AnyQuizQuestion =
| QuizQuestionVariant | QuizQuestionVariant
| QuizQuestionImages | QuizQuestionImages
@ -66,6 +70,8 @@ export type AnyQuizQuestion =
| QuizQuestionFile | QuizQuestionFile
| QuizQuestionPage | QuizQuestionPage
| QuizQuestionRating | QuizQuestionRating
| QuizQuestionBase; | QuizQuestionInitial;
export type QuizQuestionType = AnyQuizQuestion["type"]; export type QuizQuestionType = AnyQuizQuestion["type"];
export type DefiniteQuestionType = Exclude<QuizQuestionType, "nonselected">;

@ -415,7 +415,7 @@ export default function QuestionsPageCard({
}} }}
> >
<Box <Box
onClick={() => createQuestion(quizId, "", totalIndex + 1)} onClick={() => createQuestion(quizId, "nonselected", totalIndex + 1)}
sx={{ sx={{
display: plusVisible && !isDragging ? "flex" : "none", display: plusVisible && !isDragging ? "flex" : "none",
width: "100%", width: "100%",

@ -117,7 +117,7 @@ export const updateVariants = (
export const createQuestion = ( export const createQuestion = (
quizId: number, quizId: number,
questionType: QuizQuestionType = "", questionType: QuizQuestionType = "nonselected",
placeIndex = -1 placeIndex = -1
) => { ) => {
const id = getRandom(1000000, 10000000); const id = getRandom(1000000, 10000000);

@ -1,7 +1,7 @@
import { Box, Button, LinearProgress, Paper, Typography } from "@mui/material"; import { Box, Button, LinearProgress, Paper, Typography } from "@mui/material";
import { questionStore } from "@root/questions"; import { questionStore } from "@root/questions";
import { decrementCurrentQuestionIndex, incrementCurrentQuestionIndex, useQuizPreviewStore } from "@root/quizPreview"; import { decrementCurrentQuestionIndex, incrementCurrentQuestionIndex, useQuizPreviewStore } from "@root/quizPreview";
import { AnyQuizQuestion, QuizQuestionType } from "model/questionTypes/shared"; import { AnyQuizQuestion, DefiniteQuestionType } from "model/questionTypes/shared";
import { FC, useEffect } from "react"; import { FC, useEffect } from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft"; import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
@ -18,7 +18,7 @@ import Variant from "./QuizPreviewQuestionTypes/Variant";
import Varimg from "./QuizPreviewQuestionTypes/Varimg"; import Varimg from "./QuizPreviewQuestionTypes/Varimg";
const QuestionPreviewComponentByType: Record<QuizQuestionType, FC<any>> = { const QuestionPreviewComponentByType: Record<DefiniteQuestionType, FC<any>> = {
variant: Variant, variant: Variant,
images: Images, images: Images,
varimg: Varimg, varimg: Varimg,
@ -44,7 +44,7 @@ export default function QuizPreviewLayout() {
const currentQuestion = nonDeletedQuizQuestions[currentQuizStep]; const currentQuestion = nonDeletedQuizQuestions[currentQuizStep];
const QuestionComponent = currentQuestion const QuestionComponent = currentQuestion
? QuestionPreviewComponentByType[currentQuestion.type as QuizQuestionType] ? QuestionPreviewComponentByType[currentQuestion.type as DefiniteQuestionType]
: null; : null;
const questionElement = QuestionComponent const questionElement = QuestionComponent