/* eslint-disable @next/next/no-img-element */ import Head from "next/head"; import Navbar from "@/components/Navbar"; import {BsFileEarmarkText, BsPencil, BsStar, BsBook, BsHeadphones, BsPen, BsMegaphone} from "react-icons/bs"; import {withIronSessionSsr} from "iron-session/next"; import {sessionOptions} from "@/lib/session"; import {useEffect, useState} from "react"; import useStats from "@/hooks/useStats"; import {averageScore, totalExams} from "@/utils/stats"; import useUser from "@/hooks/useUser"; import Sidebar from "@/components/Sidebar"; import Diagnostic from "@/components/Diagnostic"; import {ToastContainer} from "react-toastify"; import {capitalize} from "lodash"; import {Module} from "@/interfaces"; import ProgressBar from "@/components/Low/ProgressBar"; import Layout from "@/components/High/Layout"; export const getServerSideProps = withIronSessionSsr(({req, res}) => { const user = req.session.user; if (!user) { res.setHeader("location", "/login"); res.statusCode = 302; res.end(); return { props: { user: null, }, }; } return { props: {user: req.session.user}, }; }, sessionOptions); export default function Home() { const [showDiagnostics, setShowDiagnostics] = useState(false); const {user} = useUser({redirectTo: "/login"}); const {stats} = useStats(user?.id); useEffect(() => { if (user) setShowDiagnostics(user.isFirstLogin); }, [user]); const calculateAverageLevel = () => { return Object.keys(user!.levels).reduce((accumulator, current) => user!.levels[current as Module] + accumulator, 0) / 4; }; if (user && showDiagnostics) { return ( <> IELTS GPT | Muscat Training Institute
setShowDiagnostics(false)} />
); } return ( <> IELTS GPT | Muscat Training Institute {user && (
{user.name}

{user.name}

{capitalize(user.type)}
{totalExams(stats)} Exams
{stats.length} Exercises
{averageScore(stats)}% Average Score
Bio Patricia Smith is a dedicated and enthusiastic student. Her passion for knowledge drives her to constantly seek new academic challenges. She is recognized for her exemplary work ethic, active participation in the classroom, and commitment to helping her peers. Her insatiable curiosity has led her to explore a wide range of areas of study, making her a versatile and adaptable learner. Patricia is a true academic leader, inspiring other students to pursue their own educational goals.
Score History
Reading Level {user.levels.reading} / Level {user.desiredLevels.reading}
Writing Level {user.levels.writing} / Level {user.desiredLevels.writing}
Listening Level {user.levels.listening} / Level {user.desiredLevels.listening}
Speaking Level {user.levels.speaking} / Level {user.desiredLevels.speaking}
)} ); }