-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
281 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
path: '/all-exercises' | ||
title: 'All exercises' | ||
hidden: false | ||
hide_in_sidebar: true | ||
course_info_page: true | ||
--- | ||
|
||
<exercises-in-all-sections></exercises-in-all-sections> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import React from "react" | ||
import PagesContext from "../../contexes/PagesContext" | ||
import styled from "styled-components" | ||
import { Paper } from "@material-ui/core" | ||
import { Link } from "gatsby" | ||
import withSimpleErrorBoundary from "../../util/withSimpleErrorBoundary" | ||
import ExerciseSummary from "../ExercisesInThisSection/ExerciseSummary" | ||
import { fetchQuizNames } from "../../services/quizzes" | ||
import { extractPartNumberFromPath, extractSubpartNumberFromPath } from "../../util/strings" | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" | ||
import { faLink } from "@fortawesome/free-solid-svg-icons" | ||
|
||
const PartWrapper = styled(Paper)` | ||
padding: 1rem; | ||
margin: 2rem 0; | ||
` | ||
|
||
const Page = styled.div` | ||
margin: 1rem 0; | ||
` | ||
|
||
const Title = styled.div` | ||
margin-bottom: 0.35em; | ||
color: rgba(0, 0, 0, 0.87); | ||
font-size: 1.5em; | ||
font-family: "Roboto", "Helvetica", "Arial", sans-serif; | ||
font-weight: 800; | ||
line-height: 1.33; | ||
letter-spacing: 0em; | ||
a { | ||
margin-left: .5em; | ||
} | ||
` | ||
|
||
const Subtitle = styled.div` | ||
margin-bottom: 0.5em; | ||
color: rgba(0, 0, 0, 0.87); | ||
font-family: "Roboto", "Helvetica", "Arial", sans-serif; | ||
font-weight: 400; | ||
font-size: 1.1rem; | ||
letter-spacing: 0em; | ||
a { | ||
margin-left: .5em; | ||
} | ||
` | ||
|
||
class ExerciseList extends React.Component { | ||
static contextType = PagesContext | ||
|
||
state = { | ||
render: false, | ||
sectionPages: null, | ||
quizIdToTitle: null, | ||
} | ||
|
||
async componentDidMount() { | ||
const value = this.context | ||
|
||
const overviewPages = value.all | ||
.filter((o) => o.overview && !o.hidden) | ||
.sort((a, b) => { | ||
let partA = extractPartNumberFromPath(a.path.toLowerCase()) | ||
let partB = extractPartNumberFromPath(b.path.toLowerCase()) | ||
|
||
return partA > partB ? 1 : partB > partA ? -1 : 0 | ||
}) | ||
|
||
const exercisePages = value.all | ||
.filter((o) => o.exercises?.length > 0) | ||
|
||
const quizIdToTitle = await fetchQuizNames() | ||
this.setState({ overviewPages, exercisePages, quizIdToTitle, render: true }) | ||
} | ||
render() { | ||
if (!this.state.render) { | ||
return <div>Loading...</div> | ||
} | ||
return ( | ||
<div> | ||
{this.state.overviewPages && | ||
this.state.overviewPages.map((page) => ( | ||
<PartWrapper key={page.title}> | ||
<Title> | ||
{page.title} | ||
<Link to={page.path}> | ||
<FontAwesomeIcon icon={faLink} size="xs" /> | ||
</Link> | ||
</Title> | ||
|
||
{this.state.exercisePages | ||
.filter((o) => o.path.startsWith(`${page.path}/`)) | ||
.sort((a, b) => { | ||
let subA = extractSubpartNumberFromPath(a.path.toLowerCase()) | ||
let subB = extractSubpartNumberFromPath(b.path.toLowerCase()) | ||
|
||
return subA > subB ? 1 : subB > subA ? -1 : 0 | ||
}) | ||
.map((page) => ( | ||
<Page key={page.title}> | ||
<Subtitle> | ||
{page.title} | ||
<Link to={page.path}> | ||
<FontAwesomeIcon icon={faLink} size="sm" /> | ||
</Link> | ||
</Subtitle> | ||
{page.exercises.map((exercise, i) => ( | ||
<ExerciseSummary | ||
index={i} | ||
exercise={exercise} | ||
key={exercise.id} | ||
quizIdToTitle={this.state.quizIdToTitle} | ||
/> | ||
))} | ||
</Page> | ||
))} | ||
</PartWrapper> | ||
)) | ||
} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default withSimpleErrorBoundary(ExerciseList) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react" | ||
import { withTranslation } from "react-i18next" | ||
import withSimpleErrorBoundary from "../../util/withSimpleErrorBoundary" | ||
import ExerciseList from "./ExerciseList" | ||
|
||
class ExercisesInAllSections extends React.Component { | ||
state = { | ||
render: false, | ||
} | ||
|
||
componentDidMount() { | ||
this.setState({ render: true }) | ||
} | ||
|
||
render() { | ||
if (!this.state.render) { | ||
return <div>Loading...</div> | ||
} | ||
return ( | ||
<ExerciseList /> | ||
) | ||
} | ||
} | ||
|
||
export default withTranslation("common")( | ||
withSimpleErrorBoundary(ExercisesInAllSections), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React, { Fragment } from "react" | ||
import { graphql } from "gatsby" | ||
import styled from "styled-components" | ||
import rehypeReact from "rehype-react" | ||
import { Helmet } from "react-helmet" | ||
|
||
import Layout from "./Layout" | ||
|
||
import getNamedPartials from "../partials" | ||
|
||
import "./remark.css" | ||
import { LoginStateContextProvider } from "../contexes/LoginStateContext" | ||
import Container from "../components/Container" | ||
import Banner from "../components/Banner" | ||
import PagesContext from "../contexes/PagesContext" | ||
|
||
const ContentWrapper = styled.article`` | ||
|
||
export default class CourseInfoTemplate extends React.Component { | ||
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 | ||
|
||
const filePath = data.page.fileAbsolutePath.substring( | ||
data.page.fileAbsolutePath.lastIndexOf("/data/"), | ||
data.page.fileAbsolutePath.length, | ||
) | ||
return ( | ||
<Fragment> | ||
<Helmet title={frontmatter.title} /> | ||
<PagesContext.Provider | ||
value={{ | ||
all: allPages, | ||
current: { frontmatter: frontmatter, filePath: filePath }, | ||
}} | ||
> | ||
<LoginStateContextProvider> | ||
<Layout> | ||
<Fragment> | ||
{frontmatter.banner && <Banner />} | ||
<Container> | ||
<ContentWrapper> | ||
<h1>{frontmatter.title}</h1> | ||
{renderAst(htmlAst)} | ||
</ContentWrapper> | ||
</Container> | ||
</Fragment> | ||
</Layout> | ||
</LoginStateContextProvider> | ||
</PagesContext.Provider> | ||
</Fragment> | ||
) | ||
} | ||
} | ||
|
||
export const pageQuery = graphql` | ||
query ($path: String!) { | ||
page: markdownRemark(frontmatter: { path: { eq: $path } }) { | ||
htmlAst | ||
html | ||
frontmatter { | ||
path | ||
title | ||
} | ||
fileAbsolutePath | ||
} | ||
allPages: allMarkdownRemark { | ||
edges { | ||
node { | ||
id | ||
frontmatter { | ||
path | ||
title | ||
overview | ||
hidden | ||
} | ||
moocfiExercises { | ||
id | ||
type | ||
parentPagePath | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters