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 { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||||
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
import { LocalAssignment } from "@/models/local/assignment/localAssignment";
|
||||||
import { rubricItemIsExtraCredit } from "@/models/local/assignment/rubricItem";
|
import { rubricItemIsExtraCredit } from "@/models/local/assignment/rubricItem";
|
||||||
|
import { assignmentPoints } from "@/models/local/assignment/utils/assignmentPointsUtils";
|
||||||
import { markdownToHTMLSafe } from "@/services/htmlMarkdownUtils";
|
import { markdownToHTMLSafe } from "@/services/htmlMarkdownUtils";
|
||||||
import React, { Fragment } from "react";
|
import React, { Fragment } from "react";
|
||||||
|
|
||||||
@@ -12,10 +13,7 @@ export default function AssignmentPreview({
|
|||||||
assignment: LocalAssignment;
|
assignment: LocalAssignment;
|
||||||
}) {
|
}) {
|
||||||
const [settings] = useLocalCourseSettingsQuery();
|
const [settings] = useLocalCourseSettingsQuery();
|
||||||
const totalPoints = assignment.rubric.reduce(
|
const totalPoints = assignmentPoints(assignment.rubric)
|
||||||
(sum, cur) => (rubricItemIsExtraCredit(cur) ? sum : sum + cur.points),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
const extraPoints = assignment.rubric.reduce(
|
const extraPoints = assignment.rubric.reduce(
|
||||||
(sum, cur) => (rubricItemIsExtraCredit(cur) ? sum + cur.points : sum),
|
(sum, cur) => (rubricItemIsExtraCredit(cur) ? sum + cur.points : sum),
|
||||||
0
|
0
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export default function EditAssignment({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const delay = 500;
|
const delay = 500;
|
||||||
|
|
||||||
const handler = setTimeout(() => {
|
const handler = setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
if (assignmentIsFetching || updateAssignment.isPending) {
|
if (assignmentIsFetching || updateAssignment.isPending) {
|
||||||
console.log("network requests in progress, not updating assignments");
|
console.log("network requests in progress, not updating assignments");
|
||||||
@@ -72,29 +72,28 @@ export default function EditAssignment({
|
|||||||
) {
|
) {
|
||||||
if (clientIsAuthoritative) {
|
if (clientIsAuthoritative) {
|
||||||
console.log("updating assignment, client is authoritative");
|
console.log("updating assignment, client is authoritative");
|
||||||
updateAssignment
|
await updateAssignment.mutateAsync({
|
||||||
.mutateAsync({
|
assignment: updatedAssignment,
|
||||||
assignment: updatedAssignment,
|
moduleName,
|
||||||
moduleName,
|
assignmentName: updatedAssignment.name,
|
||||||
assignmentName: updatedAssignment.name,
|
previousModuleName: moduleName,
|
||||||
previousModuleName: moduleName,
|
previousAssignmentName: assignmentName,
|
||||||
previousAssignmentName: assignmentName,
|
courseName,
|
||||||
courseName,
|
});
|
||||||
})
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
.then(async () => {
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
||||||
|
|
||||||
if (updatedAssignment.name !== assignmentName)
|
const newUpdatedAssignment: LocalAssignment =
|
||||||
router.replace(
|
localAssignmentMarkdown.parseMarkdown(text);
|
||||||
getModuleItemUrl(
|
if (newUpdatedAssignment.name !== assignmentName)
|
||||||
courseName,
|
router.replace(
|
||||||
moduleName,
|
getModuleItemUrl(
|
||||||
"assignment",
|
courseName,
|
||||||
updatedAssignment.name
|
moduleName,
|
||||||
),
|
"assignment",
|
||||||
{}
|
newUpdatedAssignment.name
|
||||||
);
|
),
|
||||||
});
|
{}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"client not authoritative, updating client with server assignment",
|
"client not authoritative, updating client with server assignment",
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import { RubricItem } from "../rubricItem";
|
|||||||
|
|
||||||
export const assignmentPoints = (rubric: RubricItem[]) => {
|
export const assignmentPoints = (rubric: RubricItem[]) => {
|
||||||
const basePoints = rubric
|
const basePoints = rubric
|
||||||
.map((r) =>
|
.map((r) => {
|
||||||
r.label.toLowerCase().includes("(extra credit)") ? 0 : r.points
|
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);
|
.reduce((acc, current) => (current > 0 ? acc + current : acc), 0);
|
||||||
return basePoints;
|
return basePoints;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user