diff options
author | sanine-a <sanine.not@pm.me> | 2021-04-16 15:29:12 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2021-04-16 15:29:12 -0500 |
commit | 51e7c6bd640a863843fe8050201395a3a1ea7660 (patch) | |
tree | 5369e6913113b489563a43cbba6062d249c9f6be | |
parent | 91a44ded1c9cfd661cdf98cd2cf6cceeedd2e8e9 (diff) |
add ModeSelect component
-rw-r--r-- | App.js | 44 |
1 files changed, 34 insertions, 10 deletions
@@ -15,7 +15,7 @@ const Constant = { CHARACTERS: characters, CHARACTERS_PER_LEVEL, LEVEL_NAMES: linearArray(characters.length/CHARACTERS_PER_LEVEL) - .map(n => `Level ${n+1} (${(CHARACTERS_PER_LEVEL*n)+1}-${CHARACTERS_PER_LEVEL*(n+1)})`), + .map(n => `${n+1} (Characters ${(CHARACTERS_PER_LEVEL*n)+1}-${CHARACTERS_PER_LEVEL*(n+1)})`), }; // IMPURE @@ -76,7 +76,11 @@ const App = ({state}) => { h(LevelSelect, { gameParams, handleInput: updateStateOnEvent(state, handleLevelInput), - handleFocusIn: updateStateOnEvent(state, handleLevelFocusIn), + }), + h('br'), + h(ModeSelect, { + gameParams, + handleInput: updateStateOnEvent(state, handleModeInput), }), ]); }; @@ -148,15 +152,34 @@ const GuessInput = ({value, isShaking, handleInput, handleKeyDown}) => { const LevelSelect = ({ gameParams, handleInput, handleFocusIn }) => { const { level } = gameParams; - const options = Constant.LEVEL_NAMES - .map((name, index) => - h('option', { - value: index, - }, name) - ); + const options = Constant.LEVEL_NAMES.map( + (name, index) => + h('option', { + value: index, + }, name) + ); return h('span', {}, [ - h('label', {}, 'Level: '), + h('label', {}, 'Level '), + h('select', { + onInput: handleInput, + }, options), + ]); +} + + +const ModeSelect = ({ gameParams, handleInput, handleFocusIn }) => { + const { gameMode, gameModes } = gameParams; + + const options = gameModes.map( + (mode, index) => + h('option', { + value: index, + }, mode.name) + ); + + return h('span', {}, [ + h('label', {}, 'Mode '), h('select', { onInput: handleInput, }, options), @@ -224,7 +247,8 @@ const handleLevelInput = (state, event) => { return reset(state, { level: event.target.selectedIndex }); }; -const handleLevelFocusIn = (state, event) => ({ gameParams: { level: -1 } }); +const handleModeInput = (state, event) => reset(state, { gameMode: event.target.selectedIndex }); + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |