forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoursePartOverviewTemplate.js
More file actions
112 lines (101 loc) · 2.57 KB
/
Copy pathCoursePartOverviewTemplate.js
File metadata and controls
112 lines (101 loc) · 2.57 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, { Fragment } from "react"
import { graphql } from "gatsby"
import styled from "styled-components"
import rehypeReact from "rehype-react"
import { navigate } from "gatsby"
import { Helmet } from "react-helmet"
import Layout from "./Layout"
import getNamedPartials from "../partials"
import { getCachedUserDetails } from "../services/moocfi"
import "./remark.css"
import PagesContext from "../contexes/PagesContext"
import LoginStateContext, {
LoginStateContextProvider,
} from "../contexes/LoginStateContext"
import Container from "../components/Container"
import { loggedIn } from "../services/moocfi"
const ContentWrapper = styled.div`
margin-top: 1rem;
padding-bottom: 2rem;
p {
margin-bottom: 2rem;
}
`
const Title = styled.h1``
export default class CoursePartOverviewTemplate extends React.Component {
static contextType = LoginStateContext
async componentDidMount() {
if (!loggedIn()) {
return
}
let userInfo = await getCachedUserDetails()
const research = userInfo?.extra_fields?.research
if (research === undefined) {
navigate("/missing-info")
}
}
render() {
const { data } = this.props
const { frontmatter, htmlAst } = data.page
const allPages = data.allPages.edges.map(o => {
const res = o.node?.frontmatter
res.exercises = o.node?.moocfiExercises
return res
})
const partials = getNamedPartials()
const renderAst = new rehypeReact({
createElement: React.createElement,
components: partials,
}).Compiler
return (
<PagesContext.Provider
value={{
all: allPages,
current: frontmatter,
}}
>
<Helmet title={frontmatter.title} />
<LoginStateContextProvider>
<Layout>
<Fragment>
<Container>
<ContentWrapper>
<Title>{frontmatter.title}</Title>
{renderAst(htmlAst)}
</ContentWrapper>
</Container>
</Fragment>
</Layout>
</LoginStateContextProvider>
</PagesContext.Provider>
)
}
}
export const pageQuery = graphql`
query($path: String!) {
page: markdownRemark(frontmatter: { path: { eq: $path } }) {
htmlAst
html
frontmatter {
path
title
}
}
allPages: allMarkdownRemark {
edges {
node {
id
frontmatter {
path
title
}
moocfiExercises {
id
type
parentPagePath
}
}
}
}
}
`