{$t('editor_page.right_click_to_delete')}
diff --git a/frontend/src/lib/editor/settings-card.svelte b/frontend/src/lib/editor/settings-card.svelte index 1d80891..068192e 100644 --- a/frontend/src/lib/editor/settings-card.svelte +++ b/frontend/src/lib/editor/settings-card.svelte @@ -67,11 +67,11 @@ {:else if pow_data === undefined} -Unknown Question Type (shouldn't happen)
{/if} diff --git a/frontend/src/lib/quiz_types.ts b/frontend/src/lib/quiz_types.ts index 93b3fde..5793508 100644 --- a/frontend/src/lib/quiz_types.ts +++ b/frontend/src/lib/quiz_types.ts @@ -18,7 +18,8 @@ export interface QuizData { export enum QuizQuestionType { ABCD = 'ABCD', // eslint-disable-line no-unused-vars - RANGE = 'RANGE' // eslint-disable-line no-unused-vars + RANGE = 'RANGE', // eslint-disable-line no-unused-vars + VOTING = 'VOTING' // eslint-disable-line no-unused-vars } export interface RangeQuizAnswer { @@ -33,7 +34,7 @@ export interface Question { question: string; type?: QuizQuestionType; image?: string; - answers: Answer[] | RangeQuizAnswer; + answers: Answer[] | RangeQuizAnswer | VotingAnswer[]; } export interface Answer { @@ -41,6 +42,11 @@ export interface Answer { answer: string; color?: string; } +export interface VotingAnswer { + answer: string; + image?: string; + color?: string; +} export interface EditorData { public: boolean; diff --git a/frontend/src/lib/yupSchemas.ts b/frontend/src/lib/yupSchemas.ts index 6309e1f..3f81e4a 100644 --- a/frontend/src/lib/yupSchemas.ts +++ b/frontend/src/lib/yupSchemas.ts @@ -17,6 +17,17 @@ export const ABCDQuestionSchema = yup .min(2, 'You need at least 2 answers') .max(16, "You can't have more than 16 answers"); +export const VotingQuestionSchema = yup + .array() + .of( + yup.object({ + answer: yup.string().required('You need an answer'), + image: yup.string().optional().nullable() + }) + ) + .min(2, 'You need at least 2 answers') + .max(16, "You can't have more than 16 answers"); + export const RangeQuestionSchema = yup.object({ min: yup.number(), max: yup.number(), @@ -50,9 +61,17 @@ export const dataSchema = yup.object({ "The image-url isn't valid" ) .lowercase(), - answers: yup.lazy((v) => - Array.isArray(v) ? ABCDQuestionSchema : RangeQuestionSchema - ) + answers: yup.lazy((v) => { + if (Array.isArray(v)) { + if (typeof v[0].right === 'boolean') { + return ABCDQuestionSchema; + } else { + return VotingQuestionSchema; + } + } else { + return RangeQuestionSchema; + } + }) }) ) .min(1, 'You need at least one question')