forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointsImpl.js
More file actions
76 lines (68 loc) · 1.58 KB
/
Copy pathPointsImpl.js
File metadata and controls
76 lines (68 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from "react"
import withSimpleErrorBoundary from "../../util/withSimpleErrorBoundary"
import CourseSettings from "../../../course-settings"
import { useQuery } from "@apollo/react-hooks"
import { gql } from "apollo-boost"
import { Button } from "@material-ui/core"
import OverallPoints from "./OverallPoints"
const PROGRESS = gql`
{
currentUser {
email
progress(course_id: "59314cb4-a9ca-43c9-b9a7-58c19325b44c") {
course {
id
name
}
user_course_progress {
id
progress
}
user_course_service_progresses {
id
progress
service {
id
name
}
}
}
}
}
`
const Points = props => {
const course = props.course || CourseSettings.default.slug
const { data, loading, error, refetch } = useQuery(PROGRESS)
if (loading) {
return <>Loading...</>
}
if (error) {
return <>Error while fetching progress: {error}</>
}
if (!data || !data.currentUser) {
return (
<>
<Button
onClick={() => {
refetch()
}}
>
Refresh
</Button>
<p>Please log in to see your points.</p>
</>
)
}
const points = data.currentUser.progress.user_course_progress.progress[0]
const courseName = data.currentUser.progress.course.name
return (
<>
<OverallPoints
refetch={refetch}
courseName={courseName}
progress={data.currentUser.progress}
/>
</>
)
}
export default withSimpleErrorBoundary(Points)