Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #62 from ZendyLim/feature/#50_goi_quiz
Browse files Browse the repository at this point in the history
Feature/#50 goi quiz
  • Loading branch information
andy1dx authored Jun 3, 2018
2 parents 43b4a4c + 3368012 commit c50a80f
Show file tree
Hide file tree
Showing 13 changed files with 510 additions and 101 deletions.
8 changes: 7 additions & 1 deletion app/component/correct.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ class CorrectPanel extends Component {


_renderQuestion(){

displayToText = this.props.question.type == 'kanji' ? this.props.question.kanji : this.props.question.moji;

return(
<View style={[ styles.correctContainer, styles.shadow ]}>
<View>
<Text style={ styles.correctText }>{ this.props.question.moji }</Text>
<Text style={ styles.correctText }>{ this.stripSpace(displayToText) }</Text>
<Text style={ styles.correctText }>{ this.props.question.romaji }</Text>
<Text style={ styles.correctHighlight }>English</Text>
<Text style={ styles.correctText }>{ this.props.question.english }</Text>
Expand Down Expand Up @@ -107,6 +109,10 @@ class CorrectPanel extends Component {

}

stripSpace(val){
return val.replace(/\s/g,'');
}

}
module.exports = CorrectPanel;

Expand Down
248 changes: 248 additions & 0 deletions app/component/fillBlank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
import React, { Component } from 'react';
import { TouchableHighlight, Image, View, Text } from 'react-native';
import PropTypes from 'prop-types';
import Icon from 'react-native-vector-icons/FontAwesome';

/**
Quiz Button
**/
class FillBlank extends Component {
static propTypes = {
textDisplay: PropTypes.string.isRequired,
textData: PropTypes.object,
id: PropTypes.string,
isCorrect: PropTypes.number,
styleFormat: PropTypes.string,
extraChar: PropTypes.string,
format: PropTypes.string
};

constructor(props) {
super(props);

this.state = {
emptyBox:[],
answerButton:[]
}
this.current = '';
this.answerLength = 0;
}

_renderIcon(){
let iconName = '';

switch (this.props.isCorrect) {
case 1:
iconName = 'circle-o';
break;

case 0:
iconName = 'times';
break;

default:
return null;
break;
}

return(
<View style={[ styles.quizBtnIconWrapper, this.props.isCorrect ? styles.quizBtnIconCorrect : styles.quizBtnIconWrong, styles.quizBtnIconLeft ]}>
<Icon name={ iconName } style={ [ styles.quizBtnIcon ] } />
</View>
);

}

setFillButtons(){
if(this.current != this.props.textDisplay){
this.current = this.props.textDisplay;

let answerString = this.props.textDisplay;
let answerStringArray = [];
let willEmpty = [];
let extraString = this.props.extraChar;

answerString = answerString.split(' ');

this.emptyBox = [];
this.answerLength = answerString.length;

ctr = 0;
while(ctr < 2){
randomIndex = Math.floor(Math.random() * this.answerLength);
if(willEmpty.indexOf(randomIndex) > -1) continue;

willEmpty[willEmpty.length] = randomIndex;
ctr++;
}

for(i = 0; i < this.answerLength; i++){
char = answerString[i];
selected = true;
hide = true;
if(willEmpty.indexOf(i) > -1){
char = '';
selected = false;
hide = false;
}

answerStringArray[i] = {
selected: selected,
char: answerString[i],
hide: hide
};

this.emptyBox[i] = {
char:char,
key:'',
clickable: !hide
};
}

for(i = 0; i < extraString.length; i++){
answerStringArray[i] = {
selected: false,
char: extraString[i]
};
}


this.shuffledString = this.shuffle(answerStringArray);
}

}

_renderFillBlankEmpty(hide){
if(!hide){
return(
<View style={[ styles.fillEmptyBox, styles.fillItem ]}></View>
);
}
else{
return null;
}

}

_renderFillAnswerBox(item, key){
if(item.clickable){
return(
(<TouchableHighlight style={[ styles.fillBox, styles.fillItem ]} onPress={ this.removeFill.bind(this,key) }>
<Text style={ styles.fillText }>{ item.char }</Text>
</TouchableHighlight>)
);
}
else{
return(
<View style={[ styles.fillBlank ]}>
<Text style={ styles.fillText }>{ item.char }</Text>
</View>
);
}


}

render(){
this.setFillButtons();
return (
<View style={ [ styles.quizBtnContainer ] }>
{ this._renderIcon() }
<View style={[ styles.displayInlineContainer, styles.fillBlankWrapper, styles.shadow ]}>
{ this.emptyBox.map((item, key)=>(
<View style={ styles.displayInline } key={key}>
{ !item.char ?
(<View style={[ styles.fillEmptyBox, styles.fillItem ]}></View>) :
(this._renderFillAnswerBox(item, key))
}
</View>

)
)}
</View>
<View style={ [styles.displayInlineContainer, styles.fillItemWrapper] }>
{ this.shuffledString.map((item, key)=>(
<View style={ styles.displayInline } key={key}>
{ item.selected ?
(this._renderFillBlankEmpty(item.hide)) :
(<TouchableHighlight style={[ styles.fillBox, styles.fillItem ]} onPress={ this.fillSelect.bind(this,key) }>
<Text style={ styles.fillText }>{ item.char }</Text>
</TouchableHighlight>)
}
</View>

)
)}
</View>
</View>
);
}

onSelectAnswer(val){
this.props.onSelectAnswer(val);

}

fillSelect = (key) => {
this.shuffledString[key].selected = true;

this.fillEmpty(this.shuffledString[key].char,key);

this.setState({
answerButton: this.shuffledString
});
}

fillEmpty(char,key) {
filled = [];
fillBox = true;
for(i = 0; i < this.answerLength; i++){
if(fillBox && !this.emptyBox[i].char){
this.emptyBox[i].char = char;
this.emptyBox[i].key = key;
fillBox = false;
}

if(this.emptyBox[i].char) filled[filled.length] = this.emptyBox[i].char;

}
console.log(this.shuffledString.length, 'wee', filled.length);
if(filled.length == this.shuffledString.length){

this.onSelectAnswer(filled.join(''));
}
}

removeFill(key) {

this.emptyBox[key].char = '';
this.shuffledString[this.emptyBox[key].key].selected = false;

this.setState({
answerButton: this.shuffledString
});
}

shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;

// While there remain elements to shuffle...
while (0 !== currentIndex) {

// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}

return array;
}

}
module.exports = FillBlank;

const styles = require('../styles/style');
26 changes: 17 additions & 9 deletions app/component/fillButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class FillButton extends Component {
isCorrect: PropTypes.number,
styleFormat: PropTypes.string,
extraChar: PropTypes.string,
format: PropTypes.string
};

constructor(props) {
Expand Down Expand Up @@ -45,7 +46,7 @@ class FillButton extends Component {
}

return(
<View style={[ styles.quizBtnIconWrapper, this.props.isCorrect ? styles.quizBtnIconCorrect : styles.quizBtnIconWrong, this.props.styleFormat != 'quizSquared' && styles.quizBtnIconLeft ]}>
<View style={[ styles.quizBtnIconWrapper, this.props.isCorrect ? styles.quizBtnIconCorrect : styles.quizBtnIconWrong, styles.quizBtnIconLeft ]}>
<Icon name={ iconName } style={ [ styles.quizBtnIcon ] } />
</View>
);
Expand All @@ -59,10 +60,16 @@ class FillButton extends Component {
let answerString = this.props.textDisplay;
let extraString = this.props.extraChar;

answerString = answerString.split('');
if(this.props.format == 'arrange'){
answerString = answerString.split(' ');
}
else{
answerString = answerString.split('');
}


this.emptyBox = [];
this.answerLength = answerString.length;
this.answerLength = answerString.length;

for(i = 0; i < this.answerLength; i++){
answerString[i] = {
Expand Down Expand Up @@ -94,7 +101,7 @@ class FillButton extends Component {
return (
<View style={ [ styles.quizBtnContainer ] }>
{ this._renderIcon() }
<View style={[ styles.displayInlineContainer, styles.fillAnswer ]}>
<View style={[ styles.displayInlineContainer, styles.fillItemWrapper ]}>
{ this.emptyBox.map((item, key)=>(
<View style={ styles.displayInline } key={key}>
{ !item.char ?
Expand All @@ -108,7 +115,7 @@ class FillButton extends Component {
)
)}
</View>
<View style={ styles.displayInlineContainer }>
<View style={ [styles.displayInlineContainer, styles.fillItemWrapper] }>
{ this.shuffledString.map((item, key)=>(
<View style={ styles.displayInline } key={key}>
{ item.selected ?
Expand Down Expand Up @@ -142,7 +149,7 @@ class FillButton extends Component {
}

fillEmpty(char,key) {
filled = '';
filled = [];
fillBox = true;
for(i = 0; i < this.answerLength; i++){
if(fillBox && !this.emptyBox[i].char){
Expand All @@ -151,12 +158,13 @@ class FillButton extends Component {
fillBox = false;
}

filled += this.emptyBox[i].char;
if(this.emptyBox[i].char) filled[filled.length] = this.emptyBox[i].char;

}
console.log(filled);
console.log(this.shuffledString.length, 'wee', filled.length);
if(filled.length == this.shuffledString.length){

this.onSelectAnswer(filled);
this.onSelectAnswer(filled.join(''));
}
}

Expand Down
10 changes: 7 additions & 3 deletions app/component/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Header extends Component {
icon: PropTypes.string,
route: PropTypes.string,
confirm: PropTypes.bool,
confirmMessage: PropTypes.string
confirmMessage: PropTypes.string,
testCall:PropTypes.func
};

constructor(props) {
Expand Down Expand Up @@ -56,7 +57,7 @@ class Header extends Component {

onClickIcon = () => {

if(confirm){
if(this.props.confirm){
this.props.testCall(false);

setTimeout(() => {
Expand All @@ -81,7 +82,10 @@ class Header extends Component {
}

proceedNavigate(){
this.props.testCall(false);
if(this.props.confirm){
this.props.testCall(false);
}

if(this.props.route){
this.props.navigation.navigate(this.props.route);
}
Expand Down
Loading

0 comments on commit c50a80f

Please sign in to comment.