diff options
| author | sanine-a <sanine.not@pm.me> | 2021-04-13 13:03:55 -0500 | 
|---|---|---|
| committer | sanine-a <sanine.not@pm.me> | 2021-04-13 13:03:55 -0500 | 
| commit | 64c6fb119164afcfc654ccee3c2ad96426f17a0c (patch) | |
| tree | 97cd91d4b741e71b9dd143f480322546cc79a6df /App.js | |
| parent | 268b82d0efbc49ff48e1f2c4b7b6c620a099f6e3 (diff) | |
add StyleDropdown.js
Diffstat (limited to 'App.js')
| -rw-r--r-- | App.js | 114 | 
1 files changed, 65 insertions, 49 deletions
| @@ -1,4 +1,9 @@  let state = { +   level: 1, +    +   levelCharacters: [], +   index: 0, +        character: '你',     pinyin: 'ni3', @@ -10,10 +15,6 @@ let state = {     inputShaking: false,  }; -let internalState = {}; - -const KEY_ENTER = 13; -  function setState(update)  { @@ -23,32 +24,61 @@ function setState(update)  } -const CurrentCharacter = function({character}) +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +const opts = [ +   'Hello, world!', +   'Goodbye, world!', +   'What\'s up, doc?', +]; + +const App = function()  { +   const { +      character, pinyin, +      hintLevel, +      inputValue, inputShaking +   } = state; +     return h( -      'h1', -      { onClick: () => setState({currentCharacter: '我'}) }, -      character +      'div', {}, +      [ +         h('h1', {}, character), +          +         h(InputBox, +           { value: inputValue, +             shaking: inputShaking, +             handleKeyDown: handleInputKeyDown, +           }), + +         h('br'), +         h('br'), + +         h(HintButton, +           { +              answer: pinyin, +              hintLevel, +              handleClick: () => setState({ hintLevel: hintLevel+1 }), +           }), + +         h(StyleDropdown, +           { options: opts, +             index: -1, +             defaultText: 'Dropdown', +           }), +      ]     );  } -function shakeInputBox() -{ -   setState({ inputShaking: true }); -   setTimeout(() => setState({ inputShaking: false }), 300); -} +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  function handleInputKeyDown(event)  {     const KEY_ENTER = 13; -   const { pinyin, inputValue } = state;     if (event.keyCode === KEY_ENTER) { -      if (inputValue === pinyin) -         correctAnswer(); -      else -         shakeInputBox(); +      makeGuess();     }     else {        setTimeout(() => setState({ @@ -58,6 +88,18 @@ function handleInputKeyDown(event)  } +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +function makeGuess() +{ +   const { inputValue, pinyin } = state; +    +   if (inputValue === pinyin) +         correctAnswer(); +      else +         shakeInputBox(); +} +  function correctAnswer()  {     setState({ @@ -66,38 +108,12 @@ function correctAnswer()     });  } - -const App = function() +function shakeInputBox()  { -   const { -      character, pinyin, -      hintLevel, -      inputValue, inputShaking -   } = state; +   setState({ inputShaking: true }); +   setTimeout(() => setState({ inputShaking: false }), 300); +} -   console.log(inputValue); -    -   return h( -      'div', {}, -      [ -         h(CurrentCharacter, -           { character, }), -          -         h(InputBox, -           { value: inputValue, -             shaking: inputShaking, -             handleKeyDown: handleInputKeyDown, -           }), -         h('br'), -         h('br'), +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -         h(HintButton, -           { -              answer: pinyin, -              hintLevel, -              handleClick: () => setState({ hintLevel: hintLevel+1 }), -           }), -         ] -      ); -   } | 
