mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
updates to rubric totals
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user