Added approach to archive past assignments

This commit is contained in:
Joao Ramos
2024-02-18 11:46:08 +00:00
parent 703fb0df5f
commit cdfafb3eea
5 changed files with 100 additions and 11 deletions

View File

@@ -13,11 +13,14 @@ import {
BsPen,
} from "react-icons/bs";
import { usePDFDownload } from "@/hooks/usePDFDownload";
import { useAssignmentArchive } from "@/hooks/useAssignmentArchive";
import { uniqBy } from "lodash";
interface Props {
onClick?: () => void;
allowDownload?: boolean;
reload?: Function;
allowArchive?: boolean;
}
export default function AssignmentCard({
@@ -29,11 +32,14 @@ export default function AssignmentCard({
assignees,
results,
exams,
archived,
onClick,
allowDownload,
reload,
allowArchive,
}: Assignment & Props) {
const { users } = useUsers();
const renderPdfIcon = usePDFDownload("assignments");
const renderArchiveIcon = useAssignmentArchive(id, reload);
const calculateAverageModuleScore = (module: Module) => {
const resultModuleBandScores = results.map((r) => {
@@ -41,11 +47,11 @@ export default function AssignmentCard({
const correct = moduleStats.reduce(
(acc, curr) => acc + curr.score.correct,
0,
0
);
const total = moduleStats.reduce(
(acc, curr) => acc + curr.score.total,
0,
0
);
return calculateBandScore(correct, total, module, r.type);
});
@@ -64,8 +70,13 @@ export default function AssignmentCard({
<div className="flex flex-col gap-3">
<div className="flex flex-row justify-between">
<h3 className="text-xl font-semibold">{name}</h3>
{allowDownload &&
renderPdfIcon(id, "text-mti-gray-dim", "text-mti-gray-dim")}
<div className="flex gap-2">
{allowDownload &&
renderPdfIcon(id, "text-mti-gray-dim", "text-mti-gray-dim")}
{allowArchive &&
!archived &&
renderArchiveIcon("text-mti-gray-dim", "text-mti-gray-dim")}
</div>
</div>
<ProgressBar
color={results.length / assignees.length < 0.5 ? "red" : "purple"}
@@ -94,7 +105,7 @@ export default function AssignmentCard({
module === "listening" && "bg-ielts-listening",
module === "writing" && "bg-ielts-writing",
module === "speaking" && "bg-ielts-speaking",
module === "level" && "bg-ielts-level",
module === "level" && "bg-ielts-level"
)}
>
{module === "reading" && <BsBook className="h-4 w-4" />}