Navigation rework, added prompt edit to components that were missing

This commit is contained in:
Carlos-Mesquita
2024-11-25 16:50:46 +00:00
parent e9b7bd14cc
commit 114da173be
105 changed files with 3761 additions and 3728 deletions

View File

@@ -1,12 +1,12 @@
import {Module} from "@/interfaces";
import {Exercise} from "@/interfaces/exam";
import {Stat} from "@/interfaces/user";
import {uniq} from "lodash";
import {groupBySession} from "./stats";
import { Module } from "@/interfaces";
import { Exercise } from "@/interfaces/exam";
import { Stat } from "@/interfaces/user";
import { uniq } from "lodash";
import { groupBySession } from "./stats";
export const MODULE_ARRAY: Module[] = ["reading", "listening", "writing", "speaking", "level"];
export const moduleLabels: {[key in Module]: string} = {
export const moduleLabels: { [key in Module]: string } = {
listening: "Listening",
reading: "Reading",
speaking: "Speaking",
@@ -14,7 +14,7 @@ export const moduleLabels: {[key in Module]: string} = {
level: "Level",
};
export const sortByModule = (a: {module: Module; [key: string]: any}, b: {module: Module; [key: string]: any}) => {
export const sortByModule = (a: { module: Module;[key: string]: any }, b: { module: Module;[key: string]: any }) => {
return MODULE_ARRAY.findIndex((x) => a.module === x) - MODULE_ARRAY.findIndex((x) => b.module === x);
};
@@ -26,15 +26,51 @@ export const countExercises = (exercises: Exercise[]) => {
const lengthMap = exercises.map((e) => {
if (e.type === "multipleChoice") return e.questions.length;
if (e.type === "interactiveSpeaking") return e.prompts.length;
if (e.type === "fillBlanks") return e.words.length;
if (e.type === "writeBlanks") return e.solutions.length;
if (e.type === "fillBlanks") return e.solutions.length;
if (e.type === "writeBlanks") return e.solutions.length
if (e.type === "matchSentences") return e.sentences.length;
if (e.type === "trueFalse") return e.questions.length;
return 1;
});
return lengthMap.reduce((accumulator, current) => accumulator + current, 0);
};
}
export const countCurrentExercises = (
exercises: Exercise[],
exerciseIndex: number,
questionIndex?: number
) => {
return exercises.reduce((acc, exercise, index) => {
if (index > exerciseIndex) {
return acc;
}
let count = 0;
if (exercise.type === "multipleChoice") {
if (index === exerciseIndex && questionIndex !== undefined) {
count = questionIndex + 1;
} else {
count = exercise.questions!.length;
}
} else if (exercise.type === "interactiveSpeaking") {
count = exercise.prompts.length;
} else if (exercise.type === "fillBlanks") {
count = exercise.solutions.length;
} else if (exercise.type === "writeBlanks") {
count = exercise.solutions.length;
} else if (exercise.type === "matchSentences") {
count = exercise.sentences.length;
} else if (exercise.type === "trueFalse") {
count = exercise.questions.length;
} else {
count = 1;
}
return acc + count;
}, 0);
};
export const countFullExams = (stats: Stat[]) => {
const sessionExams = groupBySession(stats);