2020-01-22 07:58:35 +01:00
|
|
|
import React, {useContext} from "react"
|
|
|
|
|
import { WordListPickerContext } from "../contexts/wordListPickerContext";
|
|
|
|
|
import { WordFeederContext } from "../contexts/wordFeederContext";
|
|
|
|
|
|
|
|
|
|
export default React.memo(function WordListPicker() {
|
|
|
|
|
|
|
|
|
|
const {setWordListCategory} = useContext(WordListPickerContext)
|
2020-01-28 02:39:11 +01:00
|
|
|
const {resetFeeder, setOrder} = useContext(WordFeederContext)
|
|
|
|
|
|
|
|
|
|
const orderOpts = ['sequential', 'random']
|
2020-01-22 07:58:35 +01:00
|
|
|
|
|
|
|
|
function handleClick(e) {
|
|
|
|
|
resetFeeder()
|
2020-01-28 02:39:11 +01:00
|
|
|
|
|
|
|
|
if (orderOpts.includes(e.target.id)) {
|
|
|
|
|
let buttons = document.querySelector(".mode-picker#wordOrderPicker").childNodes
|
|
|
|
|
buttons.forEach(button => {
|
|
|
|
|
if (button.id === e.target.id) {
|
|
|
|
|
button.classList.add('selected')
|
|
|
|
|
} else { button.classList.remove('selected')}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
setOrder(e.target.id)
|
|
|
|
|
} else {
|
|
|
|
|
let buttons = document.querySelector(".mode-picker#wordListPicker").childNodes
|
|
|
|
|
buttons.forEach(button => {
|
|
|
|
|
if (button.id === e.target.id) {
|
|
|
|
|
button.classList.add('selected')
|
|
|
|
|
} else { button.classList.remove('selected')}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
setWordListCategory(e.target.id)
|
|
|
|
|
console.log("Switched to " + e.target.id + " mode.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-01-22 07:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2020-01-28 02:39:11 +01:00
|
|
|
<>
|
2020-01-22 07:58:35 +01:00
|
|
|
<div id="wordListPicker" className="mode-picker">
|
|
|
|
|
<button id="common100" onClick={handleClick}>
|
|
|
|
|
100 Most Common Words
|
|
|
|
|
</button>
|
|
|
|
|
<button id="alphabet" onClick={handleClick}>
|
|
|
|
|
Alphabet
|
|
|
|
|
</button>
|
|
|
|
|
<button id="test" onClick={handleClick}>
|
|
|
|
|
Test List
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2020-01-28 02:39:11 +01:00
|
|
|
<div id="wordOrderPicker" className="mode-picker">
|
|
|
|
|
<button id="sequential" onClick={handleClick}>
|
|
|
|
|
Sequential
|
|
|
|
|
</button>
|
|
|
|
|
<button id="random" onClick={handleClick}>
|
|
|
|
|
Random
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
2020-01-22 07:58:35 +01:00
|
|
|
)
|
|
|
|
|
})
|