Skip to content

Commit 4bbc05c

Browse files
committed
Remove overdue tests from My Isaac notification count
Copy f3fcf97 and necessary parts of 9da86f7 to master.
1 parent b80235c commit 4bbc05c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/app/components/navigation/NavigationBar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
isAda,
2020
isFound,
2121
isNotPartiallyLoggedIn,
22+
isOverdue,
2223
isPhy,
2324
partitionCompleteAndIncompleteQuizzes,
2425
siteSpecific
@@ -93,7 +94,7 @@ export function useAssignmentsCount() {
9394
? filterAssignmentsByStatus(assignments).inProgressRecent.length
9495
: 0;
9596
const quizzesCount = quizAssignments && isFound(quizAssignments)
96-
? partitionCompleteAndIncompleteQuizzes(quizAssignments)[1].length
97+
? partitionCompleteAndIncompleteQuizzes(quizAssignments)[1].filter(q => !isOverdue(q)).length
9798
: 0;
9899

99100
return {assignmentsCount, quizzesCount};

src/app/services/assignments.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AssignmentDTO} from "../../IsaacApiTypes";
1+
import {AssignmentDTO, IAssignmentLike} from "../../IsaacApiTypes";
22
import orderBy from "lodash/orderBy";
33
import {EnhancedAssignment} from "../../IsaacAppTypes";
44
import {API_PATH, extractTeacherName, matchesAllWordsInAnyOrder} from "./";
@@ -15,13 +15,13 @@ function createAssignmentWithStartDate(assignment: AssignmentDTO): AssignmentDTO
1515
return {...assignment, startDate: assignmentStartDate};
1616
}
1717

18+
const now = new Date();
19+
const midnightLastNight = new Date(now);
20+
midnightLastNight.setHours(0, 0, 0, 0);
21+
1822
type AssignmentStatus = "inProgressRecent" | "inProgressOld" | "allAttempted" | "allCorrect";
1923
export const filterAssignmentsByStatus = (assignments: AssignmentDTO[] | undefined | null) => {
20-
const now = new Date();
2124
const fourWeeksAgo = new Date(now.valueOf() - (4 * 7 * 24 * 60 * 60 * 1000));
22-
// Midnight last night:
23-
const midnightLastNight = new Date(now);
24-
midnightLastNight.setHours(0, 0, 0, 0);
2525

2626
const myAssignments: Record<AssignmentStatus, (AssignmentDTO & {startDate: Date})[]> = {
2727
inProgressRecent: [],
@@ -104,3 +104,5 @@ export const getDistinctAssignmentSetters = (assignments: AssignmentDTO[] | unde
104104
export const getAssignmentStartDate = (a: AssignmentDTO): number => (a.scheduledStartDate ?? a.creationDate ?? 0).valueOf();
105105

106106
export const hasAssignmentStarted = (a: AssignmentDTO): boolean => getAssignmentStartDate(a) <= Date.now();
107+
108+
export const isOverdue = (a: IAssignmentLike) => a.dueDate && a.dueDate < midnightLastNight;

0 commit comments

Comments
 (0)