forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuiz.js
More file actions
65 lines (59 loc) · 1.88 KB
/
Copy pathQuiz.js
File metadata and controls
65 lines (59 loc) · 1.88 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
import React from "react"
import styled from "styled-components"
import LoginStateContext from "../contexes/LoginStateContext"
import LoginControls from "../components/LoginControls"
import { withTranslation } from "react-i18next"
import withSimpleErrorBoundary from "../util/withSimpleErrorBoundary"
import { normalizeExerciseId } from "../util/strings"
import Quiz from "moocfi-quizzes"
import { Paper } from "@material-ui/core"
import { accessToken } from "../services/moocfi"
import CourseSettings from "../../course-settings"
const StyledPaper = styled(Paper)`
overflow: hidden;
margin: 2rem 0 2rem 0;
box-shadow: rgba(0, 0, 0, 0.3) 0px 8px 40px -12px !important;
border-radius: 1rem !important;
`
class QuizPartial extends React.Component {
static contextType = LoginStateContext
render() {
const { id, t } = this.props
let languageId = "en_US"
if (CourseSettings.default.language === "fi") {
languageId = "fi_FI"
}
if (!this.context.loggedIn) {
const loginPrompt = (
<div style={{ padding: "1rem", textAlign: "center" }}>
<p>{t("loginToSeeExercise")}</p>
<LoginControls />
</div>
)
return (
<StyledPaper id={normalizeExerciseId(`quiz-${id}`)}>
<Quiz
id={id}
languageId={languageId}
backendAddress="https://quizzes.mooc.fi"
customContent={loginPrompt}
/>
</StyledPaper>
)
}
if (!id) {
return <div>There should be quiz here but no quiz id is specified.</div>
}
return (
<StyledPaper id={normalizeExerciseId(`quiz-${id}`)}>
<Quiz
id={id}
languageId={languageId}
accessToken={accessToken()}
backendAddress="https://quizzes.mooc.fi"
/>
</StyledPaper>
)
}
}
export default withTranslation("common")(withSimpleErrorBoundary(QuizPartial))