Merged in bug-user-level-progress (pull request #37)
Bug user level progress Approved-by: Alvaro Doria
This commit is contained in:
@@ -227,7 +227,11 @@ export default function StudentDashboard({user}: Props) {
|
||||
<section className="flex flex-col gap-3">
|
||||
<span className="text-lg font-bold">Score History</span>
|
||||
<div className="-md:grid-rows-4 grid gap-6 md:grid-cols-2">
|
||||
{MODULE_ARRAY.map((module) => (
|
||||
{MODULE_ARRAY
|
||||
.map((module) => {
|
||||
const desiredLevel = user.desiredLevels[module] || 9;
|
||||
const level = user.levels[module] || 0;
|
||||
return (
|
||||
<div className="border-mti-gray-anti-flash flex flex-col gap-2 rounded-xl border p-4" key={module}>
|
||||
<div className="flex items-center gap-2 md:gap-3">
|
||||
<div className="bg-mti-gray-smoke flex h-8 w-8 items-center justify-center rounded-lg md:h-12 md:w-12 md:rounded-xl">
|
||||
@@ -240,7 +244,7 @@ export default function StudentDashboard({user}: Props) {
|
||||
<div className="flex w-full justify-between">
|
||||
<span className="text-sm font-bold md:font-extrabold">{capitalize(module)}</span>
|
||||
<span className="text-mti-gray-dim text-sm font-normal">
|
||||
Level {user.levels[module] || 0} / Level 9 (Desired Level: {user.desiredLevels[module] || 9})
|
||||
Level {level} / Level 9 (Desired Level: {desiredLevel})
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -248,14 +252,15 @@ export default function StudentDashboard({user}: Props) {
|
||||
<ProgressBar
|
||||
color={module}
|
||||
label=""
|
||||
mark={Math.round((user.desiredLevels[module] * 100) / 9)}
|
||||
markLabel={`Desired Level: ${user.desiredLevels[module]}`}
|
||||
percentage={Math.round((user.levels[module] * 100) / 9)}
|
||||
mark={Math.round((desiredLevel * 100) / 9)}
|
||||
markLabel={`Desired Level: ${desiredLevel}`}
|
||||
percentage={Math.round((level * 100) / 9)}
|
||||
className="h-2 w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
|
||||
@@ -5,6 +5,7 @@ import {Stat, User} from "@/interfaces/user";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {calculateBandScore} from "@/utils/score";
|
||||
import {groupByModule, groupBySession} from "@/utils/stats";
|
||||
import { MODULE_ARRAY } from "@/utils/moduleUtils";
|
||||
import {getAuth} from "firebase/auth";
|
||||
import {collection, doc, getDoc, getDocs, getFirestore, query, updateDoc, where} from "firebase/firestore";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
@@ -55,7 +56,7 @@ async function update(req: NextApiRequest, res: NextApiResponse) {
|
||||
},
|
||||
};
|
||||
|
||||
MODULES.forEach((module: Module) => {
|
||||
MODULE_ARRAY.forEach((module: Module) => {
|
||||
const moduleStats = sessionStats.filter((x) => x.module === module);
|
||||
if (moduleStats.length === 0) return;
|
||||
|
||||
@@ -87,11 +88,18 @@ async function update(req: NextApiRequest, res: NextApiResponse) {
|
||||
.filter((x) => x.total > 0)
|
||||
.reduce((acc, cur) => ({total: acc.total + cur.total, correct: acc.correct + cur.correct}), {total: 0, correct: 0});
|
||||
|
||||
const levelLevel = sessionLevels
|
||||
.map((x) => x.level)
|
||||
.filter((x) => x.total > 0)
|
||||
.reduce((acc, cur) => ({total: acc.total + cur.total, correct: acc.correct + cur.correct}), {total: 0, correct: 0});
|
||||
|
||||
|
||||
const levels = {
|
||||
reading: calculateBandScore(readingLevel.correct, readingLevel.total, "reading", req.session.user.focus),
|
||||
listening: calculateBandScore(listeningLevel.correct, listeningLevel.total, "listening", req.session.user.focus),
|
||||
writing: calculateBandScore(writingLevel.correct, writingLevel.total, "writing", req.session.user.focus),
|
||||
speaking: calculateBandScore(speakingLevel.correct, speakingLevel.total, "speaking", req.session.user.focus),
|
||||
level: calculateBandScore(levelLevel.correct, levelLevel.total, "level", req.session.user.focus),
|
||||
};
|
||||
|
||||
const userDoc = doc(db, "users", req.session.user.id);
|
||||
|
||||
Reference in New Issue
Block a user