Implemented Telegraph Key switching, resolved history clearing bug

This commit is contained in:
Gene Mecija 2020-01-17 12:23:17 -08:00
parent c777cf013c
commit b3436d963b
13 changed files with 86 additions and 120 deletions

View file

@ -1,24 +1,19 @@
import React, {Component} from "react"
import React, {useState} from "react"
const KeyTypeContext = React.createContext()
class KeyTypeContextProvider extends Component {
state = {
keyType: "electronic"
}
switchKeyType = (type) => {
this.setState({keyType: type})
}
function KeyTypeContextProvider(props) {
render() {
return (
<KeyTypeContext.Provider value={{keyType: this.state.keyType, switchKeyType: this.switchKeyType}}>
{this.props.children}
</KeyTypeContext.Provider>
)
}
const [keyType, setKeyType] = useState('straight')
return (
<KeyTypeContext.Provider value={{
keyType: keyType,
setKeyType: setKeyType
}}>
{props.children}
</KeyTypeContext.Provider>
)
}
export {KeyTypeContextProvider, KeyTypeContext}

View file

@ -3,28 +3,10 @@ import React, {useState} from "react"
const MorseBufferContext = React.createContext()
function MorseBufferContextProvider(props) {
// state = {
// morseCharBuffer: '',
// morseWords: []
// //morseCharBuffer, morseWords, clearHistory, setMorseCharBuffer, setMorseWords
// }
console.log('MorseBufferContextProvider LOADED');
const [morseCharBuffer, setMorseCharBuffer] = useState('')
const [morseWords, setMorseWords] = useState([])
// switchKeyType = (type = "straight") => {
// this.setState({keyType: type})
// }
// setMorseCharBuffer = (value) => {
// this.setState({morseCharBuffer: value})
// }
// setMorseWords = (value) => {
// this.setState({morseWords: value})
// }
// render() {
return (
<MorseBufferContext.Provider value={{
morseCharBuffer: morseCharBuffer,
@ -35,8 +17,6 @@ function MorseBufferContextProvider(props) {
{props.children}
</MorseBufferContext.Provider>
)
// }
}
export {MorseBufferContextProvider, MorseBufferContext}