Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | 1x 30x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 7x 1x 6x 24x | import { useEffect, useMemo } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useParams } from "react-router-dom";
import { useTheme } from "@mui/material/styles";
import { Box, Card, CardContent, CircularProgress, Grid, Stack, Typography } from "@mui/material";
import GradeIcon from "@mui/icons-material/Grade";
import DoneAllIcon from "@mui/icons-material/DoneAll";
import AssignmentTurnedInIcon from "@mui/icons-material/AssignmentTurnedIn";
import ReportProblemIcon from "@mui/icons-material/ReportProblem";
import BarChartIcon from "@mui/icons-material/BarChart";
import TimelineIcon from "@mui/icons-material/Timeline";
import PieChartIcon from "@mui/icons-material/PieChart";
import ListAltIcon from "@mui/icons-material/ListAlt";
import StatCard from "@/app/student-page/page/dashboard/components/StatCard";
import { _studentFetchClassGradeAverage } from "@/store/slices/student/StudentClassGrade";
import { bandColor, bandLabel } from "./gradeBands";
import GradeGaugeChart from "@/app/student-page/components/my-grade/GradeGaugeChart";
import StatusBreakdownChart from "@/app/student-page/components/my-grade/StatusBreakdownChart";
import AssignmentGradesBarChart from "@/app/student-page/components/my-grade/AssignmentGradesBarChart";
import GradeTrendChart from "@/app/student-page/components/my-grade/GradeTrendChart";
import AssignmentsGradeTable from "@/app/student-page/components/my-grade/AssignmentsGradeTable";
const SectionCard = ({ icon, title, subtitle, children }) => (
<Card elevation={0} sx={{ border: (t) => `1px solid ${t.palette.divider}`, borderRadius: 3, height: "100%" }}>
<CardContent>
<Stack direction="row" alignItems="center" spacing={1} sx={{ mb: subtitle ? 0.25 : 2 }}>
{icon}
<Typography variant="subtitle1" fontWeight={700}>
{title}
</Typography>
</Stack>
{subtitle && (
<Typography variant="caption" color="text.secondary" sx={{ display: "block", mb: 2 }}>
{subtitle}
</Typography>
)}
{children}
</CardContent>
</Card>
);
const MyGrade = () => {
const theme = useTheme();
const dispatch = useDispatch();
const { classCode } = useParams();
const { average, totalGraded, totalAssignments, statusCounts, assignments, isLoading, hasErrors } = useSelector(
(state) => state.StudentClassGrade
);
useEffect(() => {
Eif (classCode) {
dispatch(_studentFetchClassGradeAverage(classCode));
}
}, [classCode, dispatch]);
const completionRate = totalAssignments > 0 ? Math.round((totalGraded / totalAssignments) * 100) : null;
const needsAttention = (statusCounts?.missed ?? 0) + (statusCounts?.pending ?? 0) + (statusCounts?.rejected ?? 0);
const statCards = useMemo(
() => [
{
id: "student-my-grade-statcard-average",
icon: <GradeIcon />,
value: typeof average === "number" ? average.toFixed(2) : "—",
label: bandLabel(average) ? `Average (${bandLabel(average)})` : "Average",
color: bandColor(theme, average),
},
{
id: "student-my-grade-statcard-graded",
icon: <DoneAllIcon />,
value: `${totalGraded}/${totalAssignments}`,
label: "Graded Assignments",
color: theme.palette.info.main,
},
{
id: "student-my-grade-statcard-completion",
icon: <AssignmentTurnedInIcon />,
value: completionRate !== null ? `${completionRate}%` : "—",
label: "Completion Rate",
color: theme.palette.primary.main,
},
{
id: "student-my-grade-statcard-attention",
icon: <ReportProblemIcon />,
value: needsAttention,
label: "Needs Attention",
color: needsAttention > 0 ? theme.palette.error.main : theme.palette.success.main,
},
],
[average, totalGraded, totalAssignments, completionRate, needsAttention, theme]
);
if (isLoading) {
return (
<Box sx={{ py: 6, textAlign: "center" }}>
<CircularProgress />
</Box>
);
}
if (hasErrors) {
return (
<Typography id="student-my-grade-error" variant="body2" color="error">
Unable to load your grade. Please try again later.
</Typography>
);
}
return (
<Box id="student-my-grade-page">
<Grid container spacing={{ xs: 1.5, sm: 2 }} sx={{ mb: 3 }}>
{statCards.map((s) => (
<Grid id={s.id} size={{ xs: 6, md: 3 }} key={s.label}>
<StatCard {...s} loading={false} />
</Grid>
))}
</Grid>
<Grid container spacing={3} sx={{ mb: 3 }}>
<Grid size={{ xs: 12, md: 5 }}>
<SectionCard icon={<GradeIcon color="primary" />} title="Overall Grade">
<GradeGaugeChart
average={average}
totalGraded={totalGraded}
totalAssignments={totalAssignments}
/>
</SectionCard>
</Grid>
<Grid size={{ xs: 12, md: 7 }}>
<SectionCard
icon={<PieChartIcon color="primary" />}
title="Assignment Status Breakdown"
subtitle="Only graded assignments count toward your average"
>
<StatusBreakdownChart statusCounts={statusCounts} totalAssignments={totalAssignments} />
</SectionCard>
</Grid>
</Grid>
<Grid container spacing={3} sx={{ mb: 3 }}>
<Grid size={{ xs: 12, md: 6 }}>
<SectionCard icon={<BarChartIcon color="primary" />} title="Grades by Assignment">
<AssignmentGradesBarChart assignments={assignments} average={average} />
</SectionCard>
</Grid>
<Grid size={{ xs: 12, md: 6 }}>
<SectionCard
icon={<TimelineIcon color="primary" />}
title="Grade Trend"
subtitle="Ordered by due date"
>
<GradeTrendChart assignments={assignments} />
</SectionCard>
</Grid>
</Grid>
<SectionCard icon={<ListAltIcon color="primary" />} title="All Assignments">
<AssignmentsGradeTable assignments={assignments} />
</SectionCard>
</Box>
);
};
export default MyGrade;
|