1
1
import React , { useState } from 'react' ;
2
- import { makeStyles , Theme , createStyles } from '@material-ui/core/styles' ;
2
+ import { makeStyles , Theme , createStyles , withStyles } from '@material-ui/core/styles' ;
3
3
import styled from 'styled-components' ;
4
4
import List from '@material-ui/core/List' ;
5
5
import ListItem from '@material-ui/core/ListItem' ;
@@ -8,6 +8,7 @@ import Collapse from '@material-ui/core/Collapse';
8
8
import ExpandLess from '@material-ui/icons/ExpandLess' ;
9
9
import ExpandMore from '@material-ui/icons/ExpandMore' ;
10
10
import { Link } from 'react-router-dom' ;
11
+ import { Box , LinearProgress } from '@material-ui/core' ;
11
12
import LinearProgressWithLabel from './LinearProgressWithLabel' ;
12
13
import {
13
14
Task ,
@@ -30,6 +31,71 @@ const useStyles = makeStyles((theme: Theme) =>
30
31
} ,
31
32
} )
32
33
) ;
34
+ const MasteredProgress = withStyles ( ( theme : Theme ) =>
35
+ createStyles ( {
36
+ root : {
37
+ height : 25 ,
38
+ borderRadius : 5 ,
39
+ } ,
40
+ colorPrimary : {
41
+ backgroundColor : '#30CC30' ,
42
+ } ,
43
+ bar : {
44
+ borderRadius : 5 ,
45
+ backgroundColor : '#30CC30' ,
46
+ } ,
47
+ } )
48
+ ) ( LinearProgress ) ;
49
+
50
+ const NotStartedProgress = withStyles ( ( theme : Theme ) =>
51
+ createStyles ( {
52
+ root : {
53
+ height : 25 ,
54
+ borderRadius : 5 ,
55
+ display : 'flex' ,
56
+ justifyContent : 'right' ,
57
+ } ,
58
+ colorPrimary : {
59
+ backgroundColor : '#E0E0E0' ,
60
+ } ,
61
+ bar : {
62
+ borderRadius : 5 ,
63
+ backgroundColor : '#E0E0E0' ,
64
+ } ,
65
+ } )
66
+ ) ( LinearProgress ) ;
67
+
68
+ const NotMasteredProgress = withStyles ( ( theme : Theme ) =>
69
+ createStyles ( {
70
+ root : {
71
+ height : 25 ,
72
+ borderRadius : 5 ,
73
+ } ,
74
+ colorPrimary : {
75
+ backgroundColor : '#EA6868' ,
76
+ } ,
77
+ bar : {
78
+ borderRadius : 5 ,
79
+ backgroundColor : '#EA6868' ,
80
+ } ,
81
+ } )
82
+ ) ( LinearProgress ) ;
83
+
84
+ const AlmostMasteredProgress = withStyles ( ( theme : Theme ) =>
85
+ createStyles ( {
86
+ root : {
87
+ height : 25 ,
88
+ borderRadius : 5 ,
89
+ } ,
90
+ colorPrimary : {
91
+ backgroundColor : '#F2C94C' ,
92
+ } ,
93
+ bar : {
94
+ borderRadius : 5 ,
95
+ backgroundColor : '#F2C94C' ,
96
+ } ,
97
+ } )
98
+ ) ( LinearProgress ) ;
33
99
34
100
const DoublePaddedDiv = styled . div `
35
101
padding-left: 40px;
@@ -42,6 +108,19 @@ export interface ObjectiveDropDownProps {
42
108
tasks : TaskObjectiveProgress [ ] ;
43
109
}
44
110
111
+ function getProgressBar ( status : number ) {
112
+ if ( status === 0 ) {
113
+ return < NotStartedProgress /> ;
114
+ }
115
+ if ( status < 0.75 ) {
116
+ return < NotMasteredProgress /> ;
117
+ }
118
+ if ( status >= 0.75 && status < 1 ) {
119
+ return < AlmostMasteredProgress /> ;
120
+ }
121
+ return < MasteredProgress /> ;
122
+ }
123
+
45
124
// Handles state to open and close dropdown
46
125
function handleClick (
47
126
openObjectBool : boolean ,
@@ -54,42 +133,43 @@ function getObjectivePercent(tasks: TaskObjectiveProgress[]) {
54
133
let count = 0 ;
55
134
for ( const task of tasks ) {
56
135
const mastery = getTaskPercent ( task . mastery ) ;
57
- if ( mastery === 100 ) {
136
+ if ( mastery === 1 ) {
58
137
count ++ ;
59
138
}
60
139
}
61
- return count ;
140
+ if ( tasks . length === 0 ) {
141
+ return 0 ;
142
+ }
143
+ return count / tasks . length ;
62
144
}
63
145
64
146
function getTaskPercent ( mastery : string ) {
65
147
if ( mastery === 'NOT_GRADED' ) {
66
148
return 0 ;
67
149
}
68
150
if ( mastery === 'NOT_MASTERED' ) {
69
- return 50 ;
151
+ return 0.5 ;
70
152
}
71
153
if ( mastery === 'ALMOST_MASTERED' ) {
72
- return 75 ;
154
+ return 0. 75;
73
155
}
74
- return 100 ;
156
+ return 1 ;
75
157
}
76
158
77
- export default function TargetDropDown ( { name, tasks } : ObjectiveDropDownProps ) {
159
+ export default function ObjectiveDropDown ( { name, tasks } : ObjectiveDropDownProps ) {
78
160
const classes = useStyles ( ) ;
79
161
const [ open , setOpen ] = useState ( false ) ;
80
162
81
- const TASK_PERCENT = 100 ;
82
- const OBJECTIVE_PERCENT = 50 ;
83
-
84
163
return (
85
164
< List component = "div" disablePadding style = { { justifyContent : 'right' , width : '100%' } } >
86
165
< ListItem button onClick = { ( ) => handleClick ( open , setOpen ) } divider >
87
166
{ open ? < ExpandLess /> : < ExpandMore /> }
88
167
< ListItemText primary = { name } />
89
- < LinearProgressWithLabel
90
- className = { classes . progressBar }
91
- value = { getObjectivePercent ( tasks ) }
92
- />
168
+ < Box display = "flex" style = { { justifyContent : 'right' } } width = "80%" >
169
+ < Box width = "100%" mr = { 1 } ml = { 1 } >
170
+ { getProgressBar ( getObjectivePercent ( tasks ) ) }
171
+ </ Box >
172
+ </ Box >
93
173
</ ListItem >
94
174
95
175
< Collapse in = { open } timeout = "auto" unmountOnExit >
@@ -100,10 +180,11 @@ export default function TargetDropDown({ name, tasks }: ObjectiveDropDownProps)
100
180
< DoublePaddedDiv >
101
181
< ListItem button className = { classes . nested } divider >
102
182
< ListItemText primary = { task . task . name } />
103
- < LinearProgressWithLabel
104
- className = { classes . progressBar }
105
- value = { getTaskPercent ( task . mastery ) }
106
- />
183
+ < Box display = "flex" alignItems = "center" width = "80%" >
184
+ < Box width = "100%" mr = { 1 } ml = { 1 } >
185
+ { getProgressBar ( getTaskPercent ( task . mastery ) ) }
186
+ </ Box >
187
+ </ Box >
107
188
</ ListItem >
108
189
</ DoublePaddedDiv >
109
190
</ div >
0 commit comments