2020-01-19 04:35:11 +01:00
|
|
|
import React, { useContext } from "react"
|
2020-01-10 09:56:38 +01:00
|
|
|
import DitDahDisplay from "./DitDahDisplay"
|
|
|
|
|
import morseCode from '../data/morse-reverse.json'
|
2020-01-19 19:26:55 +01:00
|
|
|
// import { MorseBufferContext } from "../contexts/morseBufferContext"
|
2020-01-10 09:56:38 +01:00
|
|
|
|
|
|
|
|
function ChallengeBufferDisplay(props) {
|
2020-01-13 09:03:58 +01:00
|
|
|
|
2020-01-19 04:35:11 +01:00
|
|
|
// // INCREMENTING COUNTER TO MONITOR COMPONENT RELOADING
|
|
|
|
|
// // console.log('ChallengeMode')
|
|
|
|
|
// if (!document.getElementById('counter')) {
|
|
|
|
|
// let counter = document.createElement('h1')
|
|
|
|
|
// let holder = document.createElement('h3')
|
|
|
|
|
// counter.id = 'counter'
|
|
|
|
|
// holder.id = 'holder'
|
|
|
|
|
// counter.innerText = "0"
|
|
|
|
|
// document.querySelector('#main-content').appendChild(counter)
|
|
|
|
|
// document.querySelector('#main-content').appendChild(holder)
|
|
|
|
|
// } else {
|
|
|
|
|
// let num = document.getElementById('counter').innerText
|
|
|
|
|
// document.getElementById('counter').innerText = Number(num) + 1
|
|
|
|
|
// document.getElementById('holder').innerText = buffer
|
|
|
|
|
// }
|
2020-01-19 19:26:55 +01:00
|
|
|
// const {morseCharBuffer, setMorseCharBuffer} = useContext(MorseBufferContext)
|
2020-01-13 09:03:58 +01:00
|
|
|
|
2020-01-19 19:26:55 +01:00
|
|
|
const morseLetters = props.morseLetters
|
|
|
|
|
console.log('morseLetters', morseLetters);
|
|
|
|
|
const setMorseCharBuffer = props.setMorseCharBuffer
|
2020-01-10 09:56:38 +01:00
|
|
|
let ditDahs = []
|
|
|
|
|
let alphanumeric = ''
|
2020-01-19 19:26:55 +01:00
|
|
|
let incorrectIndex = props.incorrectIndex
|
2020-01-10 09:56:38 +01:00
|
|
|
|
2020-01-19 19:26:55 +01:00
|
|
|
for (let i in morseLetters) {
|
|
|
|
|
let morseChar = morseLetters[i]
|
|
|
|
|
alphanumeric += morseCode[morseChar]
|
|
|
|
|
|
|
|
|
|
let cn = ''
|
|
|
|
|
cn = (incorrectIndex === i) ? 'morseError' : ''
|
|
|
|
|
ditDahs.push(morseChar)
|
|
|
|
|
ditDahs.push(' ')
|
2020-01-10 09:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div id="challengeBufferDisplay">
|
|
|
|
|
<div id="alphanumeric-container">
|
|
|
|
|
<div id="alphanumeric">
|
|
|
|
|
{alphanumeric.toUpperCase()}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-01-19 19:26:55 +01:00
|
|
|
<div id="ditDahs">
|
|
|
|
|
{ditDahs}
|
|
|
|
|
</div>
|
2020-01-10 09:56:38 +01:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default React.memo(ChallengeBufferDisplay)
|