fix question card remounting on every id change
This commit is contained in:
parent
83d314bf48
commit
2b06bd750c
@ -1,7 +1,7 @@
|
|||||||
import type { QuizQuestionBase } from "../model/questionTypes/shared";
|
import type { QuizQuestionBase } from "../model/questionTypes/shared";
|
||||||
|
|
||||||
|
|
||||||
export const QUIZ_QUESTION_BASE: Omit<QuizQuestionBase, "id"> = {
|
export const QUIZ_QUESTION_BASE: Omit<QuizQuestionBase, "id" | "fixedId"> = {
|
||||||
quizId: 0,
|
quizId: 0,
|
||||||
description: "",
|
description: "",
|
||||||
page: 0,
|
page: 0,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
|
|
||||||
import type { QuizQuestionDate } from "../model/questionTypes/date";
|
import type { QuizQuestionDate } from "../model/questionTypes/date";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_DATE: Omit<QuizQuestionDate, "id"> = {
|
export const QUIZ_QUESTION_DATE: Omit<QuizQuestionDate, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "date",
|
type: "date",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import { QUIZ_QUESTION_VARIANT } from "./variant";
|
|||||||
import { QUIZ_QUESTION_VARIMG } from "./varimg";
|
import { QUIZ_QUESTION_VARIMG } from "./varimg";
|
||||||
|
|
||||||
|
|
||||||
export const defaultQuestionByType: Record<QuestionType, Omit<AnyQuizQuestion, "id">> = {
|
export const defaultQuestionByType: Record<QuestionType, Omit<AnyQuizQuestion, "id" | "fixedId">> = {
|
||||||
"date": QUIZ_QUESTION_DATE,
|
"date": QUIZ_QUESTION_DATE,
|
||||||
"emoji": QUIZ_QUESTION_EMOJI,
|
"emoji": QUIZ_QUESTION_EMOJI,
|
||||||
"file": QUIZ_QUESTION_FILE,
|
"file": QUIZ_QUESTION_FILE,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
import type { QuizQuestionEmoji } from "../model/questionTypes/emoji";
|
import type { QuizQuestionEmoji } from "../model/questionTypes/emoji";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_EMOJI: Omit<QuizQuestionEmoji, "id"> = {
|
export const QUIZ_QUESTION_EMOJI: Omit<QuizQuestionEmoji, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "emoji",
|
type: "emoji",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
|
|
||||||
import type { QuizQuestionFile } from "../model/questionTypes/file";
|
import type { QuizQuestionFile } from "../model/questionTypes/file";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_FILE: Omit<QuizQuestionFile, "id"> = {
|
export const QUIZ_QUESTION_FILE: Omit<QuizQuestionFile, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "file",
|
type: "file",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
import type { QuizQuestionImages } from "../model/questionTypes/images";
|
import type { QuizQuestionImages } from "../model/questionTypes/images";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_IMAGES: Omit<QuizQuestionImages, "id"> = {
|
export const QUIZ_QUESTION_IMAGES: Omit<QuizQuestionImages, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "images",
|
type: "images",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
|
|
||||||
import type { QuizQuestionNumber } from "../model/questionTypes/number";
|
import type { QuizQuestionNumber } from "../model/questionTypes/number";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_NUMBER: Omit<QuizQuestionNumber, "id"> = {
|
export const QUIZ_QUESTION_NUMBER: Omit<QuizQuestionNumber, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "number",
|
type: "number",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
|
|
||||||
import type { QuizQuestionPage } from "../model/questionTypes/page";
|
import type { QuizQuestionPage } from "../model/questionTypes/page";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_PAGE: Omit<QuizQuestionPage, "id"> = {
|
export const QUIZ_QUESTION_PAGE: Omit<QuizQuestionPage, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "page",
|
type: "page",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
|
|
||||||
import type { QuizQuestionRating } from "../model/questionTypes/rating";
|
import type { QuizQuestionRating } from "../model/questionTypes/rating";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_RATING: Omit<QuizQuestionRating, "id"> = {
|
export const QUIZ_QUESTION_RATING: Omit<QuizQuestionRating, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "rating",
|
type: "rating",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
import type { QuizQuestionSelect } from "../model/questionTypes/select";
|
import type { QuizQuestionSelect } from "../model/questionTypes/select";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_SELECT: Omit<QuizQuestionSelect, "id"> = {
|
export const QUIZ_QUESTION_SELECT: Omit<QuizQuestionSelect, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "select",
|
type: "select",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
|
|
||||||
import type { QuizQuestionText } from "../model/questionTypes/text";
|
import type { QuizQuestionText } from "../model/questionTypes/text";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_TEXT: Omit<QuizQuestionText, "id"> = {
|
export const QUIZ_QUESTION_TEXT: Omit<QuizQuestionText, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "text",
|
type: "text",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
import type { QuizQuestionVariant } from "../model/questionTypes/variant";
|
import type { QuizQuestionVariant } from "../model/questionTypes/variant";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_VARIANT: Omit<QuizQuestionVariant, "id"> = {
|
export const QUIZ_QUESTION_VARIANT: Omit<QuizQuestionVariant, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "variant",
|
type: "variant",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { QUIZ_QUESTION_BASE } from "./base";
|
|||||||
import type { QuizQuestionVarImg } from "../model/questionTypes/varimg";
|
import type { QuizQuestionVarImg } from "../model/questionTypes/varimg";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
export const QUIZ_QUESTION_VARIMG: Omit<QuizQuestionVarImg, "id"> = {
|
export const QUIZ_QUESTION_VARIMG: Omit<QuizQuestionVarImg, "id" | "fixedId"> = {
|
||||||
...QUIZ_QUESTION_BASE,
|
...QUIZ_QUESTION_BASE,
|
||||||
type: "varimg",
|
type: "varimg",
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -54,6 +54,7 @@ export function rawQuestionToQuestion(rawQuestion: RawQuestion): AnyQuizQuestion
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: rawQuestion.id,
|
id: rawQuestion.id,
|
||||||
|
fixedId: rawQuestion.id,
|
||||||
description: rawQuestion.description,
|
description: rawQuestion.description,
|
||||||
page: rawQuestion.page,
|
page: rawQuestion.page,
|
||||||
quizId: rawQuestion.quiz_id,
|
quizId: rawQuestion.quiz_id,
|
||||||
|
|||||||
@ -49,6 +49,8 @@ export interface ImageQuestionVariant extends QuestionVariant {
|
|||||||
|
|
||||||
export interface QuizQuestionBase {
|
export interface QuizQuestionBase {
|
||||||
id: number;
|
id: number;
|
||||||
|
/** fixed id for using it as a key prop */
|
||||||
|
fixedId: number;
|
||||||
quizId: number;
|
quizId: number;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export const DraggableList = () => {
|
|||||||
<Box ref={provided.innerRef} {...provided.droppableProps}>
|
<Box ref={provided.innerRef} {...provided.droppableProps}>
|
||||||
{questions.map((question, index) => (
|
{questions.map((question, index) => (
|
||||||
<DraggableListItem
|
<DraggableListItem
|
||||||
key={question.id}
|
key={question.fixedId}
|
||||||
question={question}
|
question={question}
|
||||||
isDragging={snapshot.isDraggingOver}
|
isDragging={snapshot.isDraggingOver}
|
||||||
index={index}
|
index={index}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export const FormDraggableList = () => {
|
|||||||
<Box ref={provided.innerRef} {...provided.droppableProps}>
|
<Box ref={provided.innerRef} {...provided.droppableProps}>
|
||||||
{questions.map((question, index) => (
|
{questions.map((question, index) => (
|
||||||
<FormDraggableListItem
|
<FormDraggableListItem
|
||||||
key={question.id}
|
key={question.fixedId}
|
||||||
question={question}
|
question={question}
|
||||||
questionIndex={index}
|
questionIndex={index}
|
||||||
questionData={question}
|
questionData={question}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user