analytica-frontend-lib 1.0.82 → 1.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Accordation/index.js +2 -2
- package/dist/Accordation/index.js.map +1 -1
- package/dist/Accordation/index.mjs +2 -2
- package/dist/Accordation/index.mjs.map +1 -1
- package/dist/AlertDialog/index.js +1 -1
- package/dist/AlertDialog/index.js.map +1 -1
- package/dist/AlertDialog/index.mjs +1 -1
- package/dist/AlertDialog/index.mjs.map +1 -1
- package/dist/Card/index.js +2 -2
- package/dist/Card/index.js.map +1 -1
- package/dist/Card/index.mjs +2 -2
- package/dist/Card/index.mjs.map +1 -1
- package/dist/Modal/index.js +1 -1
- package/dist/Modal/index.js.map +1 -1
- package/dist/Modal/index.mjs +1 -1
- package/dist/Modal/index.mjs.map +1 -1
- package/dist/Quiz/index.d.mts +52 -0
- package/dist/Quiz/index.d.ts +52 -0
- package/dist/Quiz/index.js +4185 -0
- package/dist/Quiz/index.js.map +1 -0
- package/dist/Quiz/index.mjs +4191 -0
- package/dist/Quiz/index.mjs.map +1 -0
- package/dist/Quiz/useQuizStore/index.d.mts +140 -0
- package/dist/Quiz/useQuizStore/index.d.ts +140 -0
- package/dist/Quiz/useQuizStore/index.js +395 -0
- package/dist/Quiz/useQuizStore/index.js.map +1 -0
- package/dist/Quiz/useQuizStore/index.mjs +367 -0
- package/dist/Quiz/useQuizStore/index.mjs.map +1 -0
- package/dist/index.css +59 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1008 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1003 -4
- package/dist/index.mjs.map +1 -1
- package/dist/simulated-result-QN5HCUY5.png +0 -0
- package/dist/styles.css +59 -0
- package/dist/styles.css.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as zustand from 'zustand';
|
|
2
|
+
|
|
3
|
+
declare enum QUESTION_DIFFICULTY {
|
|
4
|
+
FACIL = "FACIL",
|
|
5
|
+
MEDIO = "MEDIO",
|
|
6
|
+
DIFICIL = "DIFICIL"
|
|
7
|
+
}
|
|
8
|
+
declare enum QUESTION_TYPE {
|
|
9
|
+
ALTERNATIVA = "ALTERNATIVA",
|
|
10
|
+
DISSERTATIVA = "DISSERTATIVA",
|
|
11
|
+
MULTIPLA_CHOICE = "MULTIPLA_CHOICE"
|
|
12
|
+
}
|
|
13
|
+
declare enum QUESTION_STATUS {
|
|
14
|
+
APROVADO = "APROVADO",
|
|
15
|
+
REPROVADO = "REPROVADO"
|
|
16
|
+
}
|
|
17
|
+
interface Question {
|
|
18
|
+
id: string;
|
|
19
|
+
questionText: string;
|
|
20
|
+
correctOptionId: string;
|
|
21
|
+
description: string;
|
|
22
|
+
type: QUESTION_TYPE;
|
|
23
|
+
status: QUESTION_STATUS;
|
|
24
|
+
difficulty: QUESTION_DIFFICULTY;
|
|
25
|
+
examBoard: string | null;
|
|
26
|
+
examYear: string | null;
|
|
27
|
+
answerKey: string | null;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
updatedAt: string;
|
|
30
|
+
knowledgeMatrix: {
|
|
31
|
+
areaKnowledgeId: string;
|
|
32
|
+
subjectId: string;
|
|
33
|
+
topicId: string;
|
|
34
|
+
subtopicId: string;
|
|
35
|
+
contentId: string;
|
|
36
|
+
}[];
|
|
37
|
+
options: {
|
|
38
|
+
id: string;
|
|
39
|
+
option: string;
|
|
40
|
+
}[];
|
|
41
|
+
createdBy: string;
|
|
42
|
+
}
|
|
43
|
+
interface Simulado {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
category: string;
|
|
47
|
+
questions: Question[];
|
|
48
|
+
}
|
|
49
|
+
interface Atividade {
|
|
50
|
+
id: string;
|
|
51
|
+
title: string;
|
|
52
|
+
questions: Question[];
|
|
53
|
+
}
|
|
54
|
+
interface Aula {
|
|
55
|
+
id: string;
|
|
56
|
+
title: string;
|
|
57
|
+
questions: Question[];
|
|
58
|
+
}
|
|
59
|
+
interface UserAnswerItem {
|
|
60
|
+
questionId: string;
|
|
61
|
+
activityId: string;
|
|
62
|
+
userId: string;
|
|
63
|
+
answer: string | null;
|
|
64
|
+
optionId: string | null;
|
|
65
|
+
}
|
|
66
|
+
interface UserAnswer extends Question {
|
|
67
|
+
isSkipped: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface QuizState {
|
|
70
|
+
bySimulated?: Simulado;
|
|
71
|
+
byActivity?: Atividade;
|
|
72
|
+
byQuestionary?: Aula;
|
|
73
|
+
currentQuestionIndex: number;
|
|
74
|
+
selectedAnswers: Record<string, string>;
|
|
75
|
+
userAnswers: UserAnswerItem[];
|
|
76
|
+
timeElapsed: number;
|
|
77
|
+
isStarted: boolean;
|
|
78
|
+
isFinished: boolean;
|
|
79
|
+
userId: string;
|
|
80
|
+
setBySimulated: (simulado: Simulado) => void;
|
|
81
|
+
setByActivity: (atividade: Atividade) => void;
|
|
82
|
+
setByQuestionary: (aula: Aula) => void;
|
|
83
|
+
setUserId: (userId: string) => void;
|
|
84
|
+
goToNextQuestion: () => void;
|
|
85
|
+
goToPreviousQuestion: () => void;
|
|
86
|
+
goToQuestion: (index: number) => void;
|
|
87
|
+
getActiveQuiz: () => {
|
|
88
|
+
quiz: Simulado | Atividade | Aula;
|
|
89
|
+
type: 'bySimulated' | 'byActivity' | 'byQuestionary';
|
|
90
|
+
} | null;
|
|
91
|
+
selectAnswer: (questionId: string, answerId: string) => void;
|
|
92
|
+
skipQuestion: () => void;
|
|
93
|
+
addUserAnswer: (questionId: string, answerId?: string) => void;
|
|
94
|
+
startQuiz: () => void;
|
|
95
|
+
finishQuiz: () => void;
|
|
96
|
+
resetQuiz: () => void;
|
|
97
|
+
updateTime: (time: number) => void;
|
|
98
|
+
startTimer: () => void;
|
|
99
|
+
stopTimer: () => void;
|
|
100
|
+
getCurrentQuestion: () => Question | null;
|
|
101
|
+
getTotalQuestions: () => number;
|
|
102
|
+
getAnsweredQuestions: () => number;
|
|
103
|
+
getUnansweredQuestions: () => number[];
|
|
104
|
+
getSkippedQuestions: () => number;
|
|
105
|
+
getProgress: () => number;
|
|
106
|
+
isQuestionAnswered: (questionId: string) => boolean;
|
|
107
|
+
isQuestionSkipped: (questionId: string) => boolean;
|
|
108
|
+
getCurrentAnswer: () => string | undefined;
|
|
109
|
+
getQuizTitle: () => string;
|
|
110
|
+
formatTime: (seconds: number) => string;
|
|
111
|
+
getUserAnswers: () => UserAnswer[];
|
|
112
|
+
getUnansweredQuestionsFromUserAnswers: () => number[];
|
|
113
|
+
getQuestionsGroupedBySubject: () => {
|
|
114
|
+
[key: string]: Question[];
|
|
115
|
+
};
|
|
116
|
+
getUserId: () => string;
|
|
117
|
+
getUserAnswerByQuestionId: (questionId: string) => UserAnswerItem | null;
|
|
118
|
+
isQuestionAnsweredByUserAnswers: (questionId: string) => boolean;
|
|
119
|
+
getQuestionStatusFromUserAnswers: (questionId: string) => 'answered' | 'unanswered' | 'skipped';
|
|
120
|
+
getUserAnswersForActivity: () => UserAnswerItem[];
|
|
121
|
+
}
|
|
122
|
+
declare const useQuizStore: zustand.UseBoundStore<Omit<zustand.StoreApi<QuizState>, "setState" | "devtools"> & {
|
|
123
|
+
setState(partial: QuizState | Partial<QuizState> | ((state: QuizState) => QuizState | Partial<QuizState>), replace?: false | undefined, action?: (string | {
|
|
124
|
+
[x: string]: unknown;
|
|
125
|
+
[x: number]: unknown;
|
|
126
|
+
[x: symbol]: unknown;
|
|
127
|
+
type: string;
|
|
128
|
+
}) | undefined): void;
|
|
129
|
+
setState(state: QuizState | ((state: QuizState) => QuizState), replace: true, action?: (string | {
|
|
130
|
+
[x: string]: unknown;
|
|
131
|
+
[x: number]: unknown;
|
|
132
|
+
[x: symbol]: unknown;
|
|
133
|
+
type: string;
|
|
134
|
+
}) | undefined): void;
|
|
135
|
+
devtools: {
|
|
136
|
+
cleanup: () => void;
|
|
137
|
+
};
|
|
138
|
+
}>;
|
|
139
|
+
|
|
140
|
+
export { QUESTION_DIFFICULTY, QUESTION_STATUS, QUESTION_TYPE, type Question, useQuizStore };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as zustand from 'zustand';
|
|
2
|
+
|
|
3
|
+
declare enum QUESTION_DIFFICULTY {
|
|
4
|
+
FACIL = "FACIL",
|
|
5
|
+
MEDIO = "MEDIO",
|
|
6
|
+
DIFICIL = "DIFICIL"
|
|
7
|
+
}
|
|
8
|
+
declare enum QUESTION_TYPE {
|
|
9
|
+
ALTERNATIVA = "ALTERNATIVA",
|
|
10
|
+
DISSERTATIVA = "DISSERTATIVA",
|
|
11
|
+
MULTIPLA_CHOICE = "MULTIPLA_CHOICE"
|
|
12
|
+
}
|
|
13
|
+
declare enum QUESTION_STATUS {
|
|
14
|
+
APROVADO = "APROVADO",
|
|
15
|
+
REPROVADO = "REPROVADO"
|
|
16
|
+
}
|
|
17
|
+
interface Question {
|
|
18
|
+
id: string;
|
|
19
|
+
questionText: string;
|
|
20
|
+
correctOptionId: string;
|
|
21
|
+
description: string;
|
|
22
|
+
type: QUESTION_TYPE;
|
|
23
|
+
status: QUESTION_STATUS;
|
|
24
|
+
difficulty: QUESTION_DIFFICULTY;
|
|
25
|
+
examBoard: string | null;
|
|
26
|
+
examYear: string | null;
|
|
27
|
+
answerKey: string | null;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
updatedAt: string;
|
|
30
|
+
knowledgeMatrix: {
|
|
31
|
+
areaKnowledgeId: string;
|
|
32
|
+
subjectId: string;
|
|
33
|
+
topicId: string;
|
|
34
|
+
subtopicId: string;
|
|
35
|
+
contentId: string;
|
|
36
|
+
}[];
|
|
37
|
+
options: {
|
|
38
|
+
id: string;
|
|
39
|
+
option: string;
|
|
40
|
+
}[];
|
|
41
|
+
createdBy: string;
|
|
42
|
+
}
|
|
43
|
+
interface Simulado {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
category: string;
|
|
47
|
+
questions: Question[];
|
|
48
|
+
}
|
|
49
|
+
interface Atividade {
|
|
50
|
+
id: string;
|
|
51
|
+
title: string;
|
|
52
|
+
questions: Question[];
|
|
53
|
+
}
|
|
54
|
+
interface Aula {
|
|
55
|
+
id: string;
|
|
56
|
+
title: string;
|
|
57
|
+
questions: Question[];
|
|
58
|
+
}
|
|
59
|
+
interface UserAnswerItem {
|
|
60
|
+
questionId: string;
|
|
61
|
+
activityId: string;
|
|
62
|
+
userId: string;
|
|
63
|
+
answer: string | null;
|
|
64
|
+
optionId: string | null;
|
|
65
|
+
}
|
|
66
|
+
interface UserAnswer extends Question {
|
|
67
|
+
isSkipped: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface QuizState {
|
|
70
|
+
bySimulated?: Simulado;
|
|
71
|
+
byActivity?: Atividade;
|
|
72
|
+
byQuestionary?: Aula;
|
|
73
|
+
currentQuestionIndex: number;
|
|
74
|
+
selectedAnswers: Record<string, string>;
|
|
75
|
+
userAnswers: UserAnswerItem[];
|
|
76
|
+
timeElapsed: number;
|
|
77
|
+
isStarted: boolean;
|
|
78
|
+
isFinished: boolean;
|
|
79
|
+
userId: string;
|
|
80
|
+
setBySimulated: (simulado: Simulado) => void;
|
|
81
|
+
setByActivity: (atividade: Atividade) => void;
|
|
82
|
+
setByQuestionary: (aula: Aula) => void;
|
|
83
|
+
setUserId: (userId: string) => void;
|
|
84
|
+
goToNextQuestion: () => void;
|
|
85
|
+
goToPreviousQuestion: () => void;
|
|
86
|
+
goToQuestion: (index: number) => void;
|
|
87
|
+
getActiveQuiz: () => {
|
|
88
|
+
quiz: Simulado | Atividade | Aula;
|
|
89
|
+
type: 'bySimulated' | 'byActivity' | 'byQuestionary';
|
|
90
|
+
} | null;
|
|
91
|
+
selectAnswer: (questionId: string, answerId: string) => void;
|
|
92
|
+
skipQuestion: () => void;
|
|
93
|
+
addUserAnswer: (questionId: string, answerId?: string) => void;
|
|
94
|
+
startQuiz: () => void;
|
|
95
|
+
finishQuiz: () => void;
|
|
96
|
+
resetQuiz: () => void;
|
|
97
|
+
updateTime: (time: number) => void;
|
|
98
|
+
startTimer: () => void;
|
|
99
|
+
stopTimer: () => void;
|
|
100
|
+
getCurrentQuestion: () => Question | null;
|
|
101
|
+
getTotalQuestions: () => number;
|
|
102
|
+
getAnsweredQuestions: () => number;
|
|
103
|
+
getUnansweredQuestions: () => number[];
|
|
104
|
+
getSkippedQuestions: () => number;
|
|
105
|
+
getProgress: () => number;
|
|
106
|
+
isQuestionAnswered: (questionId: string) => boolean;
|
|
107
|
+
isQuestionSkipped: (questionId: string) => boolean;
|
|
108
|
+
getCurrentAnswer: () => string | undefined;
|
|
109
|
+
getQuizTitle: () => string;
|
|
110
|
+
formatTime: (seconds: number) => string;
|
|
111
|
+
getUserAnswers: () => UserAnswer[];
|
|
112
|
+
getUnansweredQuestionsFromUserAnswers: () => number[];
|
|
113
|
+
getQuestionsGroupedBySubject: () => {
|
|
114
|
+
[key: string]: Question[];
|
|
115
|
+
};
|
|
116
|
+
getUserId: () => string;
|
|
117
|
+
getUserAnswerByQuestionId: (questionId: string) => UserAnswerItem | null;
|
|
118
|
+
isQuestionAnsweredByUserAnswers: (questionId: string) => boolean;
|
|
119
|
+
getQuestionStatusFromUserAnswers: (questionId: string) => 'answered' | 'unanswered' | 'skipped';
|
|
120
|
+
getUserAnswersForActivity: () => UserAnswerItem[];
|
|
121
|
+
}
|
|
122
|
+
declare const useQuizStore: zustand.UseBoundStore<Omit<zustand.StoreApi<QuizState>, "setState" | "devtools"> & {
|
|
123
|
+
setState(partial: QuizState | Partial<QuizState> | ((state: QuizState) => QuizState | Partial<QuizState>), replace?: false | undefined, action?: (string | {
|
|
124
|
+
[x: string]: unknown;
|
|
125
|
+
[x: number]: unknown;
|
|
126
|
+
[x: symbol]: unknown;
|
|
127
|
+
type: string;
|
|
128
|
+
}) | undefined): void;
|
|
129
|
+
setState(state: QuizState | ((state: QuizState) => QuizState), replace: true, action?: (string | {
|
|
130
|
+
[x: string]: unknown;
|
|
131
|
+
[x: number]: unknown;
|
|
132
|
+
[x: symbol]: unknown;
|
|
133
|
+
type: string;
|
|
134
|
+
}) | undefined): void;
|
|
135
|
+
devtools: {
|
|
136
|
+
cleanup: () => void;
|
|
137
|
+
};
|
|
138
|
+
}>;
|
|
139
|
+
|
|
140
|
+
export { QUESTION_DIFFICULTY, QUESTION_STATUS, QUESTION_TYPE, type Question, useQuizStore };
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/Quiz/useQuizStore.ts
|
|
21
|
+
var useQuizStore_exports = {};
|
|
22
|
+
__export(useQuizStore_exports, {
|
|
23
|
+
QUESTION_DIFFICULTY: () => QUESTION_DIFFICULTY,
|
|
24
|
+
QUESTION_STATUS: () => QUESTION_STATUS,
|
|
25
|
+
QUESTION_TYPE: () => QUESTION_TYPE,
|
|
26
|
+
useQuizStore: () => useQuizStore
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(useQuizStore_exports);
|
|
29
|
+
var import_zustand = require("zustand");
|
|
30
|
+
var import_middleware = require("zustand/middleware");
|
|
31
|
+
var QUESTION_DIFFICULTY = /* @__PURE__ */ ((QUESTION_DIFFICULTY2) => {
|
|
32
|
+
QUESTION_DIFFICULTY2["FACIL"] = "FACIL";
|
|
33
|
+
QUESTION_DIFFICULTY2["MEDIO"] = "MEDIO";
|
|
34
|
+
QUESTION_DIFFICULTY2["DIFICIL"] = "DIFICIL";
|
|
35
|
+
return QUESTION_DIFFICULTY2;
|
|
36
|
+
})(QUESTION_DIFFICULTY || {});
|
|
37
|
+
var QUESTION_TYPE = /* @__PURE__ */ ((QUESTION_TYPE2) => {
|
|
38
|
+
QUESTION_TYPE2["ALTERNATIVA"] = "ALTERNATIVA";
|
|
39
|
+
QUESTION_TYPE2["DISSERTATIVA"] = "DISSERTATIVA";
|
|
40
|
+
QUESTION_TYPE2["MULTIPLA_CHOICE"] = "MULTIPLA_CHOICE";
|
|
41
|
+
return QUESTION_TYPE2;
|
|
42
|
+
})(QUESTION_TYPE || {});
|
|
43
|
+
var QUESTION_STATUS = /* @__PURE__ */ ((QUESTION_STATUS2) => {
|
|
44
|
+
QUESTION_STATUS2["APROVADO"] = "APROVADO";
|
|
45
|
+
QUESTION_STATUS2["REPROVADO"] = "REPROVADO";
|
|
46
|
+
return QUESTION_STATUS2;
|
|
47
|
+
})(QUESTION_STATUS || {});
|
|
48
|
+
var useQuizStore = (0, import_zustand.create)()(
|
|
49
|
+
(0, import_middleware.devtools)(
|
|
50
|
+
(set, get) => {
|
|
51
|
+
let timerInterval = null;
|
|
52
|
+
const startTimer = () => {
|
|
53
|
+
if (get().isFinished) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (timerInterval) {
|
|
57
|
+
clearInterval(timerInterval);
|
|
58
|
+
}
|
|
59
|
+
timerInterval = setInterval(() => {
|
|
60
|
+
const { timeElapsed } = get();
|
|
61
|
+
set({ timeElapsed: timeElapsed + 1 });
|
|
62
|
+
}, 1e3);
|
|
63
|
+
};
|
|
64
|
+
const stopTimer = () => {
|
|
65
|
+
if (timerInterval) {
|
|
66
|
+
clearInterval(timerInterval);
|
|
67
|
+
timerInterval = null;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
// Initial State
|
|
72
|
+
currentQuestionIndex: 0,
|
|
73
|
+
selectedAnswers: {},
|
|
74
|
+
userAnswers: [],
|
|
75
|
+
timeElapsed: 0,
|
|
76
|
+
isStarted: false,
|
|
77
|
+
isFinished: false,
|
|
78
|
+
userId: "",
|
|
79
|
+
// Setters
|
|
80
|
+
setBySimulated: (simulado) => set({ bySimulated: simulado }),
|
|
81
|
+
setByActivity: (atividade) => set({ byActivity: atividade }),
|
|
82
|
+
setByQuestionary: (aula) => set({ byQuestionary: aula }),
|
|
83
|
+
setUserId: (userId) => set({ userId }),
|
|
84
|
+
getUserId: () => get().userId,
|
|
85
|
+
// Navigation
|
|
86
|
+
goToNextQuestion: () => {
|
|
87
|
+
const { currentQuestionIndex, getTotalQuestions } = get();
|
|
88
|
+
const totalQuestions = getTotalQuestions();
|
|
89
|
+
if (currentQuestionIndex < totalQuestions - 1) {
|
|
90
|
+
set({ currentQuestionIndex: currentQuestionIndex + 1 });
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
goToPreviousQuestion: () => {
|
|
94
|
+
const { currentQuestionIndex } = get();
|
|
95
|
+
if (currentQuestionIndex > 0) {
|
|
96
|
+
set({ currentQuestionIndex: currentQuestionIndex - 1 });
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
goToQuestion: (index) => {
|
|
100
|
+
const { getTotalQuestions } = get();
|
|
101
|
+
const totalQuestions = getTotalQuestions();
|
|
102
|
+
if (index >= 0 && index < totalQuestions) {
|
|
103
|
+
set({ currentQuestionIndex: index });
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
getActiveQuiz: () => {
|
|
107
|
+
const { bySimulated, byActivity, byQuestionary } = get();
|
|
108
|
+
if (bySimulated)
|
|
109
|
+
return { quiz: bySimulated, type: "bySimulated" };
|
|
110
|
+
if (byActivity)
|
|
111
|
+
return { quiz: byActivity, type: "byActivity" };
|
|
112
|
+
if (byQuestionary)
|
|
113
|
+
return { quiz: byQuestionary, type: "byQuestionary" };
|
|
114
|
+
return null;
|
|
115
|
+
},
|
|
116
|
+
selectAnswer: (questionId, answerId) => {
|
|
117
|
+
const { getActiveQuiz, userAnswers } = get();
|
|
118
|
+
const activeQuiz = getActiveQuiz();
|
|
119
|
+
if (!activeQuiz) return;
|
|
120
|
+
const updatedQuestions = activeQuiz.quiz.questions.map(
|
|
121
|
+
(question) => question.id === questionId ? { ...question, answerKey: answerId } : question
|
|
122
|
+
);
|
|
123
|
+
const updatedQuiz = {
|
|
124
|
+
...activeQuiz.quiz,
|
|
125
|
+
questions: updatedQuestions
|
|
126
|
+
};
|
|
127
|
+
const activityId = activeQuiz.quiz.id;
|
|
128
|
+
const userId = get().getUserId();
|
|
129
|
+
if (!userId) {
|
|
130
|
+
console.warn("selectAnswer called before userId is set");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const existingAnswerIndex = userAnswers.findIndex(
|
|
134
|
+
(answer) => answer.questionId === questionId
|
|
135
|
+
);
|
|
136
|
+
const newUserAnswer = {
|
|
137
|
+
questionId,
|
|
138
|
+
activityId,
|
|
139
|
+
userId,
|
|
140
|
+
answer: answerId,
|
|
141
|
+
optionId: answerId
|
|
142
|
+
};
|
|
143
|
+
let updatedUserAnswers;
|
|
144
|
+
if (existingAnswerIndex !== -1) {
|
|
145
|
+
updatedUserAnswers = [...userAnswers];
|
|
146
|
+
updatedUserAnswers[existingAnswerIndex] = newUserAnswer;
|
|
147
|
+
} else {
|
|
148
|
+
updatedUserAnswers = [...userAnswers, newUserAnswer];
|
|
149
|
+
}
|
|
150
|
+
set({
|
|
151
|
+
[activeQuiz.type]: updatedQuiz,
|
|
152
|
+
userAnswers: updatedUserAnswers
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
skipQuestion: () => {
|
|
156
|
+
const { getCurrentQuestion, userAnswers, getActiveQuiz } = get();
|
|
157
|
+
const currentQuestion = getCurrentQuestion();
|
|
158
|
+
const activeQuiz = getActiveQuiz();
|
|
159
|
+
if (!activeQuiz) return;
|
|
160
|
+
if (currentQuestion) {
|
|
161
|
+
const activityId = activeQuiz.quiz.id;
|
|
162
|
+
const userId = get().getUserId();
|
|
163
|
+
const existingAnswerIndex = userAnswers.findIndex(
|
|
164
|
+
(answer) => answer.questionId === currentQuestion.id
|
|
165
|
+
);
|
|
166
|
+
const newUserAnswer = {
|
|
167
|
+
questionId: currentQuestion.id,
|
|
168
|
+
activityId,
|
|
169
|
+
userId,
|
|
170
|
+
answer: null,
|
|
171
|
+
optionId: null
|
|
172
|
+
};
|
|
173
|
+
let updatedUserAnswers;
|
|
174
|
+
if (existingAnswerIndex !== -1) {
|
|
175
|
+
updatedUserAnswers = [...userAnswers];
|
|
176
|
+
updatedUserAnswers[existingAnswerIndex] = newUserAnswer;
|
|
177
|
+
} else {
|
|
178
|
+
updatedUserAnswers = [...userAnswers, newUserAnswer];
|
|
179
|
+
}
|
|
180
|
+
set({
|
|
181
|
+
userAnswers: updatedUserAnswers
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
addUserAnswer: (questionId, answerId) => {
|
|
186
|
+
const { getActiveQuiz, userAnswers } = get();
|
|
187
|
+
const activeQuiz = getActiveQuiz();
|
|
188
|
+
if (!activeQuiz) return;
|
|
189
|
+
const activityId = activeQuiz.quiz.id;
|
|
190
|
+
const userId = get().getUserId();
|
|
191
|
+
const existingAnswerIndex = userAnswers.findIndex(
|
|
192
|
+
(answer) => answer.questionId === questionId
|
|
193
|
+
);
|
|
194
|
+
const newUserAnswer = {
|
|
195
|
+
questionId,
|
|
196
|
+
activityId,
|
|
197
|
+
userId,
|
|
198
|
+
answer: answerId || null,
|
|
199
|
+
optionId: answerId || null
|
|
200
|
+
};
|
|
201
|
+
if (existingAnswerIndex !== -1) {
|
|
202
|
+
const updatedUserAnswers = [...userAnswers];
|
|
203
|
+
updatedUserAnswers[existingAnswerIndex] = newUserAnswer;
|
|
204
|
+
set({ userAnswers: updatedUserAnswers });
|
|
205
|
+
} else {
|
|
206
|
+
set({ userAnswers: [...userAnswers, newUserAnswer] });
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
startQuiz: () => {
|
|
210
|
+
set({ isStarted: true, timeElapsed: 0 });
|
|
211
|
+
startTimer();
|
|
212
|
+
},
|
|
213
|
+
finishQuiz: () => {
|
|
214
|
+
set({ isFinished: true });
|
|
215
|
+
stopTimer();
|
|
216
|
+
},
|
|
217
|
+
resetQuiz: () => {
|
|
218
|
+
stopTimer();
|
|
219
|
+
set({
|
|
220
|
+
currentQuestionIndex: 0,
|
|
221
|
+
selectedAnswers: {},
|
|
222
|
+
userAnswers: [],
|
|
223
|
+
timeElapsed: 0,
|
|
224
|
+
isStarted: false,
|
|
225
|
+
isFinished: false,
|
|
226
|
+
userId: ""
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
// Timer
|
|
230
|
+
updateTime: (time) => set({ timeElapsed: time }),
|
|
231
|
+
startTimer,
|
|
232
|
+
stopTimer,
|
|
233
|
+
// Getters
|
|
234
|
+
getCurrentQuestion: () => {
|
|
235
|
+
const { currentQuestionIndex, getActiveQuiz } = get();
|
|
236
|
+
const activeQuiz = getActiveQuiz();
|
|
237
|
+
if (!activeQuiz) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
return activeQuiz.quiz.questions[currentQuestionIndex];
|
|
241
|
+
},
|
|
242
|
+
getTotalQuestions: () => {
|
|
243
|
+
const { getActiveQuiz } = get();
|
|
244
|
+
const activeQuiz = getActiveQuiz();
|
|
245
|
+
return activeQuiz?.quiz?.questions?.length || 0;
|
|
246
|
+
},
|
|
247
|
+
getAnsweredQuestions: () => {
|
|
248
|
+
const { userAnswers } = get();
|
|
249
|
+
return userAnswers.filter((answer) => answer.answer !== null).length;
|
|
250
|
+
},
|
|
251
|
+
getUnansweredQuestions: () => {
|
|
252
|
+
const { getActiveQuiz, userAnswers } = get();
|
|
253
|
+
const activeQuiz = getActiveQuiz();
|
|
254
|
+
if (!activeQuiz) return [];
|
|
255
|
+
const unansweredQuestions = [];
|
|
256
|
+
activeQuiz.quiz.questions.forEach((question, index) => {
|
|
257
|
+
const userAnswer = userAnswers.find(
|
|
258
|
+
(answer) => answer.questionId === question.id
|
|
259
|
+
);
|
|
260
|
+
const isAnswered = userAnswer && userAnswer.answer !== null;
|
|
261
|
+
const isSkipped = userAnswer && userAnswer.answer === null;
|
|
262
|
+
if (!isAnswered && !isSkipped) {
|
|
263
|
+
unansweredQuestions.push(index + 1);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return unansweredQuestions;
|
|
267
|
+
},
|
|
268
|
+
getSkippedQuestions: () => {
|
|
269
|
+
const { userAnswers } = get();
|
|
270
|
+
return userAnswers.filter((answer) => answer.answer === null).length;
|
|
271
|
+
},
|
|
272
|
+
getProgress: () => {
|
|
273
|
+
const { getTotalQuestions, getAnsweredQuestions } = get();
|
|
274
|
+
const total = getTotalQuestions();
|
|
275
|
+
const answered = getAnsweredQuestions();
|
|
276
|
+
return total > 0 ? answered / total * 100 : 0;
|
|
277
|
+
},
|
|
278
|
+
isQuestionAnswered: (questionId) => {
|
|
279
|
+
const { userAnswers } = get();
|
|
280
|
+
const userAnswer = userAnswers.find(
|
|
281
|
+
(answer) => answer.questionId === questionId
|
|
282
|
+
);
|
|
283
|
+
return userAnswer ? userAnswer.answer !== null : false;
|
|
284
|
+
},
|
|
285
|
+
isQuestionSkipped: (questionId) => {
|
|
286
|
+
const { userAnswers } = get();
|
|
287
|
+
const userAnswer = userAnswers.find(
|
|
288
|
+
(answer) => answer.questionId === questionId
|
|
289
|
+
);
|
|
290
|
+
return userAnswer ? userAnswer.answer === null : false;
|
|
291
|
+
},
|
|
292
|
+
getCurrentAnswer: () => {
|
|
293
|
+
const { getCurrentQuestion, userAnswers } = get();
|
|
294
|
+
const currentQuestion = getCurrentQuestion();
|
|
295
|
+
if (!currentQuestion) return void 0;
|
|
296
|
+
const userAnswer = userAnswers.find(
|
|
297
|
+
(answer) => answer.questionId === currentQuestion.id
|
|
298
|
+
);
|
|
299
|
+
return userAnswer?.answer;
|
|
300
|
+
},
|
|
301
|
+
getQuizTitle: () => {
|
|
302
|
+
const { getActiveQuiz } = get();
|
|
303
|
+
const activeQuiz = getActiveQuiz();
|
|
304
|
+
return activeQuiz?.quiz?.title || "Quiz";
|
|
305
|
+
},
|
|
306
|
+
formatTime: (seconds) => {
|
|
307
|
+
const minutes = Math.floor(seconds / 60);
|
|
308
|
+
const remainingSeconds = seconds % 60;
|
|
309
|
+
return `${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
|
|
310
|
+
},
|
|
311
|
+
getUserAnswers: () => {
|
|
312
|
+
const { getActiveQuiz, userAnswers } = get();
|
|
313
|
+
const activeQuiz = getActiveQuiz();
|
|
314
|
+
if (!activeQuiz) return [];
|
|
315
|
+
return activeQuiz.quiz.questions.map((question) => {
|
|
316
|
+
const userAnswer = userAnswers.find(
|
|
317
|
+
(answer) => answer.questionId === question.id
|
|
318
|
+
);
|
|
319
|
+
return {
|
|
320
|
+
...question,
|
|
321
|
+
isSkipped: userAnswer ? userAnswer.answer === null : false
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
getUnansweredQuestionsFromUserAnswers: () => {
|
|
326
|
+
const { getActiveQuiz, userAnswers } = get();
|
|
327
|
+
const activeQuiz = getActiveQuiz();
|
|
328
|
+
if (!activeQuiz) return [];
|
|
329
|
+
const unansweredQuestions = [];
|
|
330
|
+
activeQuiz.quiz.questions.forEach((question, index) => {
|
|
331
|
+
const userAnswer = userAnswers.find(
|
|
332
|
+
(answer) => answer.questionId === question.id
|
|
333
|
+
);
|
|
334
|
+
const hasAnswer = userAnswer && userAnswer.answer !== null;
|
|
335
|
+
const isSkipped = userAnswer && userAnswer.answer === null;
|
|
336
|
+
if (!hasAnswer || isSkipped) {
|
|
337
|
+
unansweredQuestions.push(index + 1);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return unansweredQuestions;
|
|
341
|
+
},
|
|
342
|
+
getQuestionsGroupedBySubject: () => {
|
|
343
|
+
const { getActiveQuiz } = get();
|
|
344
|
+
const activeQuiz = getActiveQuiz();
|
|
345
|
+
if (!activeQuiz) return {};
|
|
346
|
+
const groupedQuestions = {};
|
|
347
|
+
activeQuiz.quiz.questions.forEach((question) => {
|
|
348
|
+
const subjectId = question.knowledgeMatrix?.[0]?.subjectId || "Sem mat\xE9ria";
|
|
349
|
+
if (!groupedQuestions[subjectId]) {
|
|
350
|
+
groupedQuestions[subjectId] = [];
|
|
351
|
+
}
|
|
352
|
+
groupedQuestions[subjectId].push(question);
|
|
353
|
+
});
|
|
354
|
+
return groupedQuestions;
|
|
355
|
+
},
|
|
356
|
+
// New methods for userAnswers
|
|
357
|
+
getUserAnswerByQuestionId: (questionId) => {
|
|
358
|
+
const { userAnswers } = get();
|
|
359
|
+
return userAnswers.find((answer) => answer.questionId === questionId) || null;
|
|
360
|
+
},
|
|
361
|
+
isQuestionAnsweredByUserAnswers: (questionId) => {
|
|
362
|
+
const { userAnswers } = get();
|
|
363
|
+
const answer = userAnswers.find(
|
|
364
|
+
(answer2) => answer2.questionId === questionId
|
|
365
|
+
);
|
|
366
|
+
return answer ? answer.answer !== null : false;
|
|
367
|
+
},
|
|
368
|
+
getQuestionStatusFromUserAnswers: (questionId) => {
|
|
369
|
+
const { userAnswers } = get();
|
|
370
|
+
const answer = userAnswers.find(
|
|
371
|
+
(answer2) => answer2.questionId === questionId
|
|
372
|
+
);
|
|
373
|
+
if (!answer) return "unanswered";
|
|
374
|
+
if (answer.answer === null) return "skipped";
|
|
375
|
+
return "answered";
|
|
376
|
+
},
|
|
377
|
+
getUserAnswersForActivity: () => {
|
|
378
|
+
const { userAnswers } = get();
|
|
379
|
+
return userAnswers;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
name: "quiz-store"
|
|
385
|
+
}
|
|
386
|
+
)
|
|
387
|
+
);
|
|
388
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
389
|
+
0 && (module.exports = {
|
|
390
|
+
QUESTION_DIFFICULTY,
|
|
391
|
+
QUESTION_STATUS,
|
|
392
|
+
QUESTION_TYPE,
|
|
393
|
+
useQuizStore
|
|
394
|
+
});
|
|
395
|
+
//# sourceMappingURL=index.js.map
|