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

Commit

Permalink
#50 fix navigations and timer in quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidborredom committed Jun 5, 2018
1 parent efa7342 commit 0b1aa3a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 55 deletions.
6 changes: 3 additions & 3 deletions app/component/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class TimerBar extends Component {
}

timerStart(){


this.duration = this.props.time;
this.seconds = this.duration / 1000;

Animated.timing(this.progress, {
duration: this.duration,
Expand Down Expand Up @@ -130,7 +130,7 @@ class TimerBar extends Component {
}

timerResume(){
if(this.props.timerResume){
if(this.props.timerResume){
this.timerStart();
}
}
Expand Down
88 changes: 56 additions & 32 deletions app/screens/Quiz/quizFlash.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ import {
this.timerResume = false;
this.time = 6000;


this.state = {
this.initialState = {
timesUp: false,
expression: 'default',
time:this.time,
Expand All @@ -108,6 +107,7 @@ import {
showCorrect:false
}

this.state = this.initialState;

this._onSetLanguageTo('en');
}
Expand Down Expand Up @@ -211,7 +211,7 @@ import {
index: navigation.getParam('index', null),
isTopicTest: navigation.getParam('isTopicTest', null)
}

console.log(navigation.getParam('index', null),'sss');
this.setState(this.initialParams);

this.setInitial();
Expand All @@ -232,11 +232,11 @@ import {
}
else{
shuffledQuiz = this.shuffleItems(this.quizItems);
console.log(shuffledQuiz,'a--');

this.allQuestion = shuffledQuiz.map((question) =>
this.shuffleAnswers(question, shuffledQuiz)
);
console.log(this.allQuestion,'s--');

this.currentQuestion = this.allQuestion[0];

this.setState({
Expand Down Expand Up @@ -267,7 +267,8 @@ import {
}

componentWillUnmount(){
this.mounted = false;
this.mounted = false;

}

// set items
Expand Down Expand Up @@ -361,7 +362,8 @@ import {
// randomized question
shuffleItems(array) {
var currentIndex = array.length, temporaryValue, randomIndex, output = [];
var limit = this.initialParams.type == 'Test' ? 25 : array.length;
var limit = this.initialParams.type == 'Test' ? 5 : array.length;


while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
Expand All @@ -371,10 +373,8 @@ import {
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}

for(i = 0; i < limit; i++){
output[i] = array[i];
}

output = array.slice(0, limit);

return output;
};
Expand Down Expand Up @@ -534,7 +534,7 @@ import {
paramFormat.time = time;
paramFormat.format = quizFormat[randomIndex];

console.log(paramFormat.time,'time2',this.time);

this.setState(paramFormat);
}

Expand All @@ -543,35 +543,51 @@ import {

if(this.mounted){
this.setTakeQuiz();

if(counter < this.allQuestion.length){
this.showCorrect = false;
this.timeStops = 0;
this.currentQuestion = this.allQuestion[counter];

this.randomQuizFormat();

this.setState({
counter: counter,
//questionId: questionId,
question: this.currentQuestion,
answerOptions: this.currentQuestion.answerOption,
answer: '',
timerRun:true,
timerRestart:true,
timesUp: false,
expression:'default',
correct: 0,
showCorrect:false
});
reset = {
counter: counter,
//questionId: questionId,
question: this.currentQuestion,
answerOptions: this.currentQuestion.answerOption,
answer: '',
timerRun:true,
timerRestart:true,
timesUp: false,
expression:'default',
correct: 0,
showCorrect:false
};
console.log(reset, 'check-res');
this.setState(reset);
}
else{
this.setEndQuiz();

this.props.navigation.navigate('ScoreScreen',{
index : this.state.index,
typeQuiz : this.state.type,
studyTitle : this.title
console.log(this.initialParams);
const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({
routeName: "ScoreScreen",
params: this.initialParams
})
]
});

this.setState(this.initialState);
this.props.navigation.dispatch(resetAction);

// this.props.navigation.navigate('ScoreScreen',{
// index : this.state.index,
// typeQuiz : this.state.type,
// studyTitle : this.title
// });

}
}
Expand Down Expand Up @@ -628,7 +644,9 @@ import {
};

goNextQuestion() {
this.setNextQuestion();
setTimeout(() => {
this.setNextQuestion();
}, this.state.pause);
}

onTimesUp = (val) => {
Expand Down Expand Up @@ -715,7 +733,13 @@ import {
};

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

}


Expand Down
65 changes: 46 additions & 19 deletions app/screens/Study/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@ import {
constructor(props) {
super(props);

this.item = [];
}
state = {
typeQuiz: ""
}

componentDidMount() {
const { navigation } = this.props;
this.setState({
initialParams = {
typeQuiz: navigation.getParam('typeQuiz', null),
index: navigation.getParam('index', null),
});
headerTitle: navigation.getParam('headerTitle', null),
studyType: navigation.getParam('studyType', null),
}

//this.processData(navigation.getParam('studyTitle', null));

//Console.log(navigation.getParam('userName', null),"NIAMAK");
this.item = StudyList[initialParams.index];
this.item['index'] = initialParams.index;
this.item['studyType'] = initialParams.studyType;
//this.item['headerTitle'] = this.item.title;
this.item['headerTitle'] = initialParams.headerTitle;
console.log(this.item);
}
goToTopicSelection = () => {
goToTopicSelection = () => {

if(this.state.typeQuiz == 'Test'){
const resetAction = NavigationActions.reset({
index: 0,
Expand All @@ -54,28 +61,48 @@ import {
]
});
this.props.navigation.dispatch(resetAction);

}else{
this.retry();
}
}

retry = () => {
var item = StudyList[this.state.index ];
item['index'] = this.state.index;
item['studyType'] = item.title;
item['headerTitle'] = item.title;

const resetAction = NavigationActions.reset({
index: 1,
actions: [
NavigationActions.navigate({ routeName: 'StudyList' }),
NavigationActions.navigate({ routeName: 'HiraganaList' , params: item })

]
});

var nav = this.setNav(this.state.type, 1);

const resetAction = NavigationActions.reset(nav);

this.props.navigation.dispatch(resetAction);

}

setNav(type, index) {
let nav;

if(this.headerTitle == 'topic_test'){
nav = {
index: index,
actions: [
NavigationActions.navigate({ routeName: 'StudyList' }),
NavigationActions.navigate({ routeName: 'TopicList' , params: this.item })
]
};
}
else{
console.log(this.item);
nav = {
index: index,
actions: [
NavigationActions.navigate({ routeName: 'StudyList' }),
NavigationActions.navigate({ routeName: 'HiraganaList' , params: this.item })
]
};
}

return nav;
}

gotToNext = () => {
var item = StudyList[this.state.index + 1];
item['index'] = this.state.index + 1;
Expand Down
2 changes: 1 addition & 1 deletion app/screens/Study/topiclist.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TopicListScreen extends Component {
type: navigation.getParam('type', null),
index: navigation.getParam('index', null),
});

console.log(navigation.getParam('index', null));
//Console.log(navigation.getParam('userName', null),"NIAMAK");
}

Expand Down
2 changes: 2 additions & 0 deletions app/screens/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class MainScreen extends Component {

// Render any loading content that you like here
render() {


if (this.props.data) {

if (this.props.data._id) {
return (
<MainStack />
Expand Down

0 comments on commit 0b1aa3a

Please sign in to comment.