From d400440a55072d92363c252888ee1127cfbbd344 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Wed, 4 Dec 2024 16:26:19 -0700 Subject: [PATCH] updates to rubric totals --- .../[assignmentName]/AssignmentPreview.tsx | 6 +-- .../[assignmentName]/EditAssignment.tsx | 45 +++++++++---------- .../assignment/utils/assignmentPointsUtils.ts | 8 ++-- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentPreview.tsx b/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentPreview.tsx index 592a8d6..6aabc00 100644 --- a/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentPreview.tsx +++ b/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentPreview.tsx @@ -3,6 +3,7 @@ import { SuspenseAndErrorHandling } from "@/components/SuspenseAndErrorHandling" import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks"; import { LocalAssignment } from "@/models/local/assignment/localAssignment"; import { rubricItemIsExtraCredit } from "@/models/local/assignment/rubricItem"; +import { assignmentPoints } from "@/models/local/assignment/utils/assignmentPointsUtils"; import { markdownToHTMLSafe } from "@/services/htmlMarkdownUtils"; import React, { Fragment } from "react"; @@ -12,10 +13,7 @@ export default function AssignmentPreview({ assignment: LocalAssignment; }) { const [settings] = useLocalCourseSettingsQuery(); - const totalPoints = assignment.rubric.reduce( - (sum, cur) => (rubricItemIsExtraCredit(cur) ? sum : sum + cur.points), - 0 - ); + const totalPoints = assignmentPoints(assignment.rubric) const extraPoints = assignment.rubric.reduce( (sum, cur) => (rubricItemIsExtraCredit(cur) ? sum + cur.points : sum), 0 diff --git a/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx b/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx index b1f006b..c3266d6 100644 --- a/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx +++ b/nextjs/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx @@ -57,7 +57,7 @@ export default function EditAssignment({ useEffect(() => { const delay = 500; - const handler = setTimeout(() => { + const handler = setTimeout(async () => { try { if (assignmentIsFetching || updateAssignment.isPending) { console.log("network requests in progress, not updating assignments"); @@ -72,29 +72,28 @@ export default function EditAssignment({ ) { if (clientIsAuthoritative) { console.log("updating assignment, client is authoritative"); - updateAssignment - .mutateAsync({ - assignment: updatedAssignment, - moduleName, - assignmentName: updatedAssignment.name, - previousModuleName: moduleName, - previousAssignmentName: assignmentName, - courseName, - }) - .then(async () => { - await new Promise((resolve) => setTimeout(resolve, 1000)); + await updateAssignment.mutateAsync({ + assignment: updatedAssignment, + moduleName, + assignmentName: updatedAssignment.name, + previousModuleName: moduleName, + previousAssignmentName: assignmentName, + courseName, + }); + await new Promise((resolve) => setTimeout(resolve, 1000)); - if (updatedAssignment.name !== assignmentName) - router.replace( - getModuleItemUrl( - courseName, - moduleName, - "assignment", - updatedAssignment.name - ), - {} - ); - }); + const newUpdatedAssignment: LocalAssignment = + localAssignmentMarkdown.parseMarkdown(text); + if (newUpdatedAssignment.name !== assignmentName) + router.replace( + getModuleItemUrl( + courseName, + moduleName, + "assignment", + newUpdatedAssignment.name + ), + {} + ); } else { console.log( "client not authoritative, updating client with server assignment", diff --git a/nextjs/src/models/local/assignment/utils/assignmentPointsUtils.ts b/nextjs/src/models/local/assignment/utils/assignmentPointsUtils.ts index 0d10307..d168912 100644 --- a/nextjs/src/models/local/assignment/utils/assignmentPointsUtils.ts +++ b/nextjs/src/models/local/assignment/utils/assignmentPointsUtils.ts @@ -2,9 +2,11 @@ import { RubricItem } from "../rubricItem"; export const assignmentPoints = (rubric: RubricItem[]) => { const basePoints = rubric - .map((r) => - r.label.toLowerCase().includes("(extra credit)") ? 0 : r.points - ) + .map((r) => { + if (r.label.toLowerCase().includes("(extra credit)")) return 0; + if (r.points < 0) return 0; // don't count negative points towards the point totals + return r.points; + }) .reduce((acc, current) => (current > 0 ? acc + current : acc), 0); return basePoints; };