Skip to content

Commit ed14771

Browse files
authored
Add XP to Profile (#318)
* Add maxGrade and xp to state * Pass props to Profile from State * Remove IS_XP_IMPLEMENTED * Unhide betcha * Use xp and maxgrade for Profile * Update tests and format
1 parent 6580835 commit ed14771

File tree

6 files changed

+252
-65
lines changed

6 files changed

+252
-65
lines changed

src/components/assessment/__tests__/__snapshots__/index.tsx.snap

Lines changed: 224 additions & 16 deletions
Large diffs are not rendered by default.

src/components/assessment/index.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { NavLink } from 'react-router-dom'
2323

2424
import defaultCoverImage from '../../assets/default_cover_image.jpg'
2525
import AssessmentWorkspaceContainer from '../../containers/assessment/AssessmentWorkspaceContainer'
26-
import { IS_XP_IMPLEMENTED } from '../../utils/constants'
2726
import { beforeNow, getPrettyDate } from '../../utils/dateHelpers'
2827
import { assessmentCategoryLink, stringParamToInt } from '../../utils/paramParseHelpers'
2928
import {
@@ -312,16 +311,14 @@ const makeOverviewCardTitle = (
312311
setBetchaAssessment: (assessment: IAssessmentOverview | null) => void
313312
) => (
314313
<div className="row listing-title">
315-
<Text ellipsize={true} className={IS_XP_IMPLEMENTED ? 'col-xs-10' : 'col-xs-12'}>
314+
<Text ellipsize={true} className={'col-xs-10'}>
316315
<h4>{overview.title}</h4>
317316
</Text>
318-
{IS_XP_IMPLEMENTED ? (
319-
<div className="col-xs-2">
320-
<Popover content={makeMenu(overview, index, setBetchaAssessment)}>
321-
<Button icon={IconNames.MENU} minimal={true} />
322-
</Popover>
323-
</div>
324-
) : null}
317+
<div className="col-xs-2">
318+
<Popover content={makeMenu(overview, index, setBetchaAssessment)}>
319+
<Button icon={IconNames.MENU} minimal={true} />
320+
</Popover>
321+
</div>
325322
</div>
326323
)
327324

src/components/dropdown/Profile.tsx

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { Classes, Dialog, NonIdealState, ProgressBar, Spinner, Tooltip } from '@blueprintjs/core'
1+
import { Classes, Dialog, NonIdealState, ProgressBar, Spinner } from '@blueprintjs/core'
22
import { IconNames } from '@blueprintjs/icons'
33
import * as React from 'react'
44

55
import { Role } from '../../reducers/states'
6-
import { IS_XP_IMPLEMENTED } from '../../utils/constants'
76

87
type ProfileProps = OwnProps & StateProps
98

109
export type StateProps = {
11-
grade?: number
12-
maxGrade?: number
13-
maxXp?: number
10+
grade: number
11+
maxGrade: number
12+
maxXp: number
1413
name?: string
1514
role?: Role
16-
xp?: number
15+
xp: number
1716
}
1817

1918
type OwnProps = {
@@ -37,31 +36,14 @@ class Profile extends React.Component<ProfileProps> {
3736
<div className="progress">
3837
<div className="grade">
3938
<span className="label">Grade</span>
40-
<span className="value">
41-
{this.props.grade !== undefined ? this.props.grade : '???'}
42-
</span>
39+
<span className="value">{this.props.grade}</span>
4340
</div>
44-
{IS_XP_IMPLEMENTED ? (
45-
<>
46-
{/* TODO: Move tooltip out of this tenary once max grade for a
47-
user is implemented in GET /user.
48-
https://github.com/source-academy/cadet/issues/205 */}
49-
<Tooltip content="Sorry, the grade progress bar is not ready yet">
50-
<ProgressBar className="grade" animate={false} stripes={false} />
51-
</Tooltip>
52-
<div className="xp">
53-
<span className="label">XP</span>
54-
<span className="value">
55-
<Tooltip content="Sorry, the XP display is not ready yet">
56-
{this.props.xp ? this.props.xp : '???'}
57-
</Tooltip>
58-
</span>
59-
</div>
60-
<Tooltip content="Sorry, the XP progress bar is not ready yet">
61-
<ProgressBar className="xp" animate={false} stripes={false} />
62-
</Tooltip>
63-
</>
64-
) : null}
41+
<ProgressBar className="grade" animate={false} stripes={false} />
42+
<div className="xp">
43+
<span className="label">XP</span>
44+
<span className="value">{this.props.xp}</span>
45+
</div>
46+
<ProgressBar className="xp" animate={false} stripes={false} />
6547
</div>
6648
</>
6749
)

src/containers/ProfileContainer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { connect, MapStateToProps } from 'react-redux'
33
import Profile, { StateProps } from '../components/dropdown/Profile'
44
import { IState } from '../reducers/states'
55

6-
// TODO: connect to actual state once backend implements these features
76
const mapStateToProps: MapStateToProps<StateProps, {}, IState> = state => ({
87
grade: state.session.grade,
9-
maxGrade: undefined,
10-
maxXp: undefined,
8+
maxGrade: state.session.maxGrade,
9+
maxXp: state.session.maxXp,
1110
name: state.session.name,
1211
role: state.session.role,
13-
xp: undefined
12+
xp: state.session.xp
1413
})
1514

1615
export default connect(mapStateToProps)(Profile)

src/reducers/states.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ export interface ISessionState {
7878
readonly gradingOverviews?: GradingOverview[]
7979
readonly gradings: Map<number, Grading>
8080
readonly historyHelper: HistoryHelper
81+
readonly maxGrade: number
82+
readonly maxXp: number
8183
readonly refreshToken?: string
8284
readonly role?: Role
8385
readonly story?: Story
8486
readonly name?: string
87+
readonly xp: number
8588
}
8689

8790
type ReplHistory = {
@@ -247,8 +250,11 @@ export const defaultSession: ISessionState = {
247250
lastAcademyLocations: [null, null],
248251
lastGeneralLocations: [null, null]
249252
},
253+
maxGrade: 0,
254+
maxXp: 0,
250255
refreshToken: undefined,
251-
name: undefined
256+
name: undefined,
257+
xp: 0
252258
}
253259

254260
export const defaultState: IState = {

src/utils/constants.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import * as dotenv from 'dotenv'
22

33
dotenv.config()
44

5-
/* Remove this variable entirely when implemented. DO NOT just set to true;
6-
* also check that the CSS looks acceptable, since there will be className
7-
* changes. */
8-
export const IS_XP_IMPLEMENTED = false
9-
105
export const IVLE_KEY = process.env.REACT_APP_IVLE_KEY
116
export const VERSION = process.env.REACT_APP_VERSION
127
export const BACKEND_URL = process.env.REACT_APP_BACKEND_URL

0 commit comments

Comments
 (0)