From 5562995977d2230572859db32b177a8c027968e9 Mon Sep 17 00:00:00 2001 From: Antti Pilto Date: Sun, 9 Sep 2018 14:49:29 +0300 Subject: [PATCH] separating alternative hiragana & katakana characters --- .../ChooseCharacters/CharacterGroup.jsx | 2 +- .../ChooseCharacters/ChooseCharacters.jsx | 86 ++++++++++++++++--- .../ChooseCharacters/ChooseCharacters.scss | 12 ++- 3 files changed, 88 insertions(+), 12 deletions(-) diff --git a/src/components/ChooseCharacters/CharacterGroup.jsx b/src/components/ChooseCharacters/CharacterGroup.jsx index 1662e12..a8a16bf 100644 --- a/src/components/ChooseCharacters/CharacterGroup.jsx +++ b/src/components/ChooseCharacters/CharacterGroup.jsx @@ -32,7 +32,7 @@ class CharacterGroup extends Component { render() { return ( -
{ this.props.handleToggleSelect(this.props.groupName); this.changeShownChars(this.getShowableCharacters('romaji')); diff --git a/src/components/ChooseCharacters/ChooseCharacters.jsx b/src/components/ChooseCharacters/ChooseCharacters.jsx index a75d54c..420f6d9 100644 --- a/src/components/ChooseCharacters/ChooseCharacters.jsx +++ b/src/components/ChooseCharacters/ChooseCharacters.jsx @@ -9,7 +9,8 @@ class ChooseCharacters extends Component { super(props); this.state = { errMsg : '', - selectedGroups: this.props.selectedGroups + selectedGroups: this.props.selectedGroups, + showAlternatives: [] } this.startGame = this.startGame.bind(this); this.showGroupRows = this.showGroupRows.bind(this); @@ -90,19 +91,84 @@ class ChooseCharacters extends Component { this.setState({selectedGroups: newSelectedGroups}); } - showGroupRows(whichKana) { - let thisKana = kanaDictionary[whichKana]; - return Object.keys(thisKana).map(function(groupName, idx) { - return ( - = 0) + newShowAlternatives.splice(idx, 1); + else + newShowAlternatives.push(whichKana) + this.setState({showAlternatives: newShowAlternatives}); + } + + getSelectedAlternatives(whichKana) { + return this.state.selectedGroups.filter(groupName => { + return groupName.startsWith(whichKana == 'hiragana' ? 'h_' : 'k_') && + groupName.endsWith('_a'); + }).length; + } + + getAmountOfAlternatives(whichKana) { + return Object.keys(kanaDictionary[whichKana]).filter(groupName => { + return groupName.endsWith("_a"); + }).length; + } + + alternativeToggleRow(whichKana, showAlternatives) { + let checkBtn = "glyphicon glyphicon-small glyphicon-" + let status; + if(this.getSelectedAlternatives(whichKana) >= this.getAmountOfAlternatives(whichKana)) + status = 'check'; + else if(this.getSelectedAlternatives(whichKana) > 0) + status = 'check half'; + else + status = 'unchecked' + checkBtn += status + + return
this.toggleAlternative(whichKana)} + className="choose-row" + > + { + if(status == 'check') + this.selectNoneAlternative(whichKana); + else if(status == 'check half') + this.selectAllAlternative(whichKana); + else if(status == 'unchecked') + this.selectAllAlternative(whichKana); + e.stopPropagation(); + }} + > + { + showAlternatives ? + : + } + Alternative characters (ga · ba · kya · sha..) +
+ } + + showGroupRows(whichKana, showAlternatives) { + const thisKana = kanaDictionary[whichKana]; + let rows = []; + Object.keys(thisKana).forEach(function(groupName, idx) { + if(groupName.endsWith("group11_a")) + rows.push(this.alternativeToggleRow(whichKana, showAlternatives)); + + if(!groupName.endsWith("a") || showAlternatives) { + rows.push( - ); + />); + } }, this); + + return rows; } startGame() { @@ -131,7 +197,7 @@ class ChooseCharacters extends Component {
Hiragana · ひらがな
- {this.showGroupRows('hiragana')} + {this.showGroupRows('hiragana', this.state.showAlternatives.indexOf('hiragana') >= 0)}
this.selectAll('hiragana')}>All  ·  this.selectNone('hiragana')}>None @@ -144,7 +210,7 @@ class ChooseCharacters extends Component {
Katakana · カタカナ
- {this.showGroupRows('katakana')} + {this.showGroupRows('katakana', this.state.showAlternatives.indexOf('katakana') >= 0)}
this.selectAll('katakana')}>All  ·  this.selectNone('katakana')}>None diff --git a/src/components/ChooseCharacters/ChooseCharacters.scss b/src/components/ChooseCharacters/ChooseCharacters.scss index 2f99817..4f7c188 100644 --- a/src/components/ChooseCharacters/ChooseCharacters.scss +++ b/src/components/ChooseCharacters/ChooseCharacters.scss @@ -25,6 +25,13 @@ .choose-row:not(:last-child) { border-bottom: 1px #eee solid; } + .alt-row { + padding-left: 20px; + background-color: #fafafa; + } + .toggle-caret { + margin: 0 4px; + } @media (min-width: 768px) { .choose-row:hover { background-color: #f4f4f4; @@ -39,6 +46,9 @@ .glyphicon-check { color: green; } + .glyphicon-check.half { + color: #ccc; + } .glyphicon-unchecked { color: #ccc; } @@ -71,7 +81,7 @@ height: 19px; border-radius: 13px; cursor: pointer; - display: inline-block; + display: block; float: right; margin-top: 1px; }