fix: answer type error

This commit is contained in:
IlyaDoronin 2024-01-22 13:26:11 +03:00
parent 2684f9c64b
commit 0d716990f3
2 changed files with 9 additions and 6 deletions

1
.gitignore vendored

@ -23,3 +23,4 @@ widget
*.njsproj
*.sln
*.sw?
build

@ -1,10 +1,11 @@
import { create } from "zustand";
import { devtools } from "zustand/middleware";
import moment from "moment";
import type { Moment } from "moment";
type Answer = {
questionId: string;
answer: string | string[];
answer: string | string[] | Moment;
};
type OwnVariant = {
@ -29,7 +30,10 @@ export const useQuizViewStore = create<QuizViewStore>()(
)
);
export const updateAnswer = (questionId: string, answer: string | string[] | moment.Moment) => {
export const updateAnswer = (
questionId: string,
answer: string | string[] | Moment
) => {
const answers = [...useQuizViewStore.getState().answers];
const answerIndex = answers.findIndex(
(answer) => questionId === answer.questionId
@ -55,9 +59,7 @@ export const deleteAnswer = (questionId: string) => {
export const updateOwnVariant = (id: string, answer: string) => {
const ownVariants = [...useQuizViewStore.getState().ownVariants];
const ownVariantIndex = ownVariants.findIndex(
(variant) => variant.id === id
);
const ownVariantIndex = ownVariants.findIndex((variant) => variant.id === id);
if (ownVariantIndex < 0) {
ownVariants.push({