@@ -6,10 +6,10 @@ import {ShowLoading} from "../handlers/ShowLoading";
6
6
import { AppState } from "../../state/reducers" ;
7
7
import { AssignmentDTO } from "../../../IsaacApiTypes" ;
8
8
import { Card , CardBody , Container , Row , Col , Nav , NavItem , NavLink } from 'reactstrap' ;
9
- import { orderBy } from "lodash" ;
10
9
import { TitleAndBreadcrumb } from "../elements/TitleAndBreadcrumb" ;
11
10
import { extractTeacherName } from "../../services/user" ;
12
11
import { DATE_FORMATTER , STUDENTS_CRUMB } from "../../services/constants" ;
12
+ import { filterAssignmentsByStatus } from "../../services/assignments" ;
13
13
14
14
const stateToProps = ( state : AppState ) => ( state && { assignments : state . assignments } ) ;
15
15
const dispatchToProps = { loadMyAssignments, logAction} ;
@@ -76,49 +76,13 @@ const Assignments = ({assignments, showOld}: {assignments: AssignmentDTO[]; show
76
76
</ ShowLoading > ;
77
77
} ;
78
78
79
- function notMissing < T > ( item : T | undefined ) : T {
80
- if ( item === undefined ) throw new Error ( "Missing item" ) ;
81
- return item ;
82
- }
79
+
83
80
84
81
const MyAssignmentsPageComponent = ( { assignments, loadMyAssignments, logAction} : MyAssignmentsPageProps ) => {
85
82
useEffect ( ( ) => { loadMyAssignments ( ) ; } , [ ] ) ;
86
83
useEffect ( ( ) => { logAction ( { type : "VIEW_MY_ASSIGNMENTS" } ) } , [ ] ) ;
87
84
88
- const now = new Date ( ) ;
89
- const fourWeeksAgo = new Date ( now . valueOf ( ) - ( 4 * 7 * 24 * 60 * 60 * 1000 ) ) ;
90
- // Midnight five days ago:
91
- const fiveDaysAgo = new Date ( now ) ;
92
- fiveDaysAgo . setDate ( now . getDate ( ) - 5 ) ;
93
- fiveDaysAgo . setHours ( 0 , 0 , 0 , 0 ) ;
94
-
95
- const myAssignments : { inProgressRecent : AssignmentDTO [ ] ; inProgressOld : AssignmentDTO [ ] ; completed : AssignmentDTO [ ] } = {
96
- inProgressRecent : [ ] ,
97
- inProgressOld : [ ] ,
98
- completed : [ ]
99
- } ;
100
-
101
- if ( assignments ) {
102
- assignments . forEach ( assignment => {
103
- assignment . gameboard = notMissing ( assignment . gameboard ) ;
104
- assignment . creationDate = notMissing ( assignment . creationDate ) ;
105
- if ( assignment . gameboard . percentageCompleted === undefined || assignment . gameboard . percentageCompleted < 100 ) {
106
- let noDueDateButRecent = ! assignment . dueDate && ( assignment . creationDate > fourWeeksAgo ) ;
107
- let dueDateAndCurrent = assignment . dueDate && ( assignment . dueDate >= fiveDaysAgo ) ;
108
- if ( noDueDateButRecent || dueDateAndCurrent ) {
109
- // Assignment either not/only just overdue, or else set within last month but no due date.
110
- myAssignments . inProgressRecent . push ( assignment ) ;
111
- } else {
112
- myAssignments . inProgressOld . push ( assignment ) ;
113
- }
114
- } else {
115
- myAssignments . completed . push ( assignment ) ;
116
- }
117
- } ) ;
118
- myAssignments . inProgressRecent = orderBy ( myAssignments . inProgressRecent , [ "dueDate" , "creationDate" ] , [ "asc" , "desc" ] ) ;
119
- myAssignments . inProgressOld = orderBy ( myAssignments . inProgressOld , [ "dueDate" , "creationDate" ] , [ "asc" , "desc" ] ) ;
120
- myAssignments . completed = orderBy ( myAssignments . completed , [ "creationDate" ] , [ "desc" ] ) ;
121
- }
85
+ const myAssignments = filterAssignmentsByStatus ( assignments )
122
86
123
87
const [ activeTab , setActiveTab ] = useState ( 0 ) ;
124
88
0 commit comments