Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
akyoto committed Jun 9, 2018
1 parent 02b48cb commit 43f783f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 8 additions & 7 deletions elements/main-menu/main-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import Word from "scripts/Word"
import MultipleChoiceTest from "../multiple-choice-test/multiple-choice-test"
import State from "scripts/State"

const predefinedWordSets = [
"people",
"occupations",
"body",
"family"
]

export default class MainMenu extends HTMLElement {
constructor() {
super()
}

async connectedCallback() {
State.wordSets = await Promise.all(
[
"people",
"occupations",
"body",
"family"
]
.map(topic => this.parse(`/words/${topic}.txt`))
predefinedWordSets.map(topic => this.parse(`/words/${topic}.txt`))
)

for(let wordSet of State.wordSets) {
Expand Down
17 changes: 10 additions & 7 deletions elements/multiple-choice-test/multiple-choice-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ export default class MultipleChoiceTest extends HTMLElement {

constructor(questions: string[]) {
super()
this.setAttribute("questions", JSON.stringify(questions))
this.questionsInTest = questions
}

async connectedCallback() {
this.initDOM()

this.appView = document.getElementsByTagName("app-view")[0] as AppView
this.answers = [...this.getElementsByClassName("answer")] as HTMLButtonElement[]

this.startTest()
}

initDOM() {
this.question = document.createElement("div")
this.question.classList.add("question")
this.appendChild(this.question)
Expand All @@ -39,12 +48,6 @@ export default class MultipleChoiceTest extends HTMLElement {
answersContainer.appendChild(answer)
}

this.appView = document.getElementsByTagName("app-view")[0] as AppView
this.answers = [...this.getElementsByClassName("answer")] as HTMLButtonElement[]
this.questionsInTest = JSON.parse(this.getAttribute("questions")) as string[] || []

this.startTest()

// Bind event listeners at the end
for(let answer of this.answers) {
answer.addEventListener("click", e => this.onAnswerClicked(e.target as HTMLButtonElement))
Expand Down

0 comments on commit 43f783f

Please sign in to comment.