Skip to content

Commit d314e6b

Browse files
committed
Separate parts by course in points balloon, don't show point for intro if student is in advanced course
1 parent dfb4896 commit d314e6b

3 files changed

Lines changed: 83 additions & 13 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from "react"
2+
import PartProgress from "./PartProgress"
3+
4+
const CourseProgress = ({
5+
data,
6+
appliesForStudyRight,
7+
currentCourseVariant,
8+
}) => {
9+
return (
10+
data &&
11+
(currentCourseVariant === "ohja-dl" ||
12+
currentCourseVariant === "ohja-nodl" ? (
13+
<div>
14+
<h4>Ohjelmoinnin jatkokurssi</h4>
15+
{Object.entries(data).map(([name, data]) => {
16+
return (
17+
<PartProgress
18+
appliesForStudyRight={appliesForStudyRight}
19+
name={name}
20+
data={data}
21+
/>
22+
)
23+
})}
24+
</div>
25+
) : (
26+
<div>
27+
<h4>Ohjelmoinnin perusteet</h4>
28+
{Object.entries(data).map(([name, data]) => {
29+
if (name === "osa08") {
30+
return (
31+
<div>
32+
<h4>Ohjelmoinnin jatkokurssi</h4>
33+
<PartProgress
34+
appliesForStudyRight={appliesForStudyRight}
35+
name={name}
36+
data={data}
37+
/>
38+
</div>
39+
)
40+
} else {
41+
return (
42+
<PartProgress
43+
appliesForStudyRight={appliesForStudyRight}
44+
name={name}
45+
data={data}
46+
/>
47+
)
48+
}
49+
})}
50+
</div>
51+
))
52+
)
53+
}
54+
55+
export default CourseProgress

src/components/PointsBalloon/PointsBalloonContent.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import styled from "styled-components"
55
import Loading from "../Loading"
66
import { fetchProgress } from "../../services/progress"
77
import PagesContext from "../../contexes/PagesContext"
8-
import PartProgress from "./PartProgress"
98
import { getCachedUserDetails } from "../../services/moocfi"
109
import { SMALL_MEDIUM_BREAKPOINT } from "../../util/constants"
10+
import CourseProgress from "./CourseProgress"
1111

1212
const StyledModal = styled(Modal)`
1313
z-index: 500 !important;
@@ -54,6 +54,7 @@ class PointsBalloonContent extends React.Component {
5454
data: null,
5555
error: null,
5656
appliesForStudyRight: null,
57+
currentCourseVariant: null,
5758
}
5859

5960
async componentDidMount() {
@@ -63,7 +64,8 @@ class PointsBalloonContent extends React.Component {
6364
let userDetails = await getCachedUserDetails()
6465
const appliesForStudyRight =
6566
userDetails?.extra_fields?.applies_for_study_right === "t"
66-
this.setState({ data, appliesForStudyRight })
67+
const currentCourseVariant = userDetails?.extra_fields?.course_variant
68+
this.setState({ data, appliesForStudyRight, currentCourseVariant })
6769
} catch (e) {
6870
this.setState({ error: e.toString() })
6971
}
@@ -98,16 +100,11 @@ class PointsBalloonContent extends React.Component {
98100
</div>
99101
) : (
100102
<div>
101-
{this.state.data &&
102-
Object.entries(this.state.data).map(([name, data]) => {
103-
return (
104-
<PartProgress
105-
appliesForStudyRight={this.state.appliesForStudyRight}
106-
name={name}
107-
data={data}
108-
/>
109-
)
110-
})}
103+
<CourseProgress
104+
data={this.state.data}
105+
appliesForStudyRight={this.state.appliesForStudyRight}
106+
currentCourseVariant={this.state.currentCourseVariant}
107+
/>
111108
</div>
112109
)}
113110
</Fragment>

src/services/progress.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
import { fetchProgrammingProgress } from "./moocfi"
1+
import { fetchProgrammingProgress, getCachedUserDetails } from "./moocfi"
22
import { fetchCrowdsorcererProgress } from "./crowdsorcerer"
33
import { zip } from "../util/arrays"
44
import { fetchQuiznatorProgress } from "./quiznator"
55

6+
const introductionCourseGroups = [
7+
"osa01",
8+
"osa02",
9+
"osa03",
10+
"osa04",
11+
"osa05",
12+
"osa06",
13+
"osa07",
14+
]
15+
616
export async function fetchProgress() {
717
const serviceIdentifiers = ["Ohjelmointitehtävät", "Kyselyt", "Crowdsorcerer"]
818
const progressesCollection = await Promise.all([
919
fetchProgrammingProgress(),
1020
fetchQuiznatorProgress(),
1121
fetchCrowdsorcererProgress(),
1222
])
23+
const userDetails = await getCachedUserDetails()
24+
const currentCourseVariant = userDetails?.extra_fields?.course_variant
1325
const progressByGroup = {}
1426

1527
zip(serviceIdentifiers, progressesCollection).forEach(
@@ -28,6 +40,12 @@ export async function fetchProgress() {
2840
toBeDeleted.push(group)
2941
}
3042
})
43+
if (
44+
currentCourseVariant === "ohja-dl" ||
45+
currentCourseVariant === "ohja-nodl"
46+
) {
47+
introductionCourseGroups.forEach(group => toBeDeleted.push(group))
48+
}
3149
toBeDeleted.forEach(o => {
3250
delete progressByGroup[o]
3351
})

0 commit comments

Comments
 (0)