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