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

Commit

Permalink
#50 fix topic
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidborredom committed Jun 23, 2018
1 parent 47b64f1 commit dca1936
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 24 deletions.
10 changes: 6 additions & 4 deletions app/actions/helper.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { pointsList } from '../config/quizFormat';

export function countScore(studyRecord,quizItems = 0) {
export function countScore(studyRecord,quizItems = 0, byPoint = false) {
let score = 0;
let countQuest = 0;
var correct = 0;
for(var i = 0; i < studyRecord.length; ++i) {
if(studyRecord[i].correct == '1'){
if(studyRecord[i].type){
correct += pointsList[studyRecord[i].type.toLowerCase()];
}else{
console.log('run this');
}else{
correct += pointsList['initial'];
}
}
Expand All @@ -20,9 +19,12 @@ export function countScore(studyRecord,quizItems = 0) {
}
}

if(quizItems){
if(quizItems && !byPoint){
countQuest = 100;
}
else{
countQuest = quizItems * 2;
}

if(countQuest !== 0 && correct !== 0){
score = Math.floor(( correct / countQuest) * 100 );
Expand Down
4 changes: 3 additions & 1 deletion app/actions/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function getJWT(){
//================================ API FETCH ===================================

export function getAllRecord(){

return (dispatch) => {
getJWT().then( JWT => {
fetch('https://e-learning-backend.herokuapp.com/api/v1/activities',{
Expand All @@ -27,7 +28,8 @@ export function getAllRecord(){
'Content-Type': 'application/json',
},
}).then(data => data.json())
.then(json => {
.then(json => {

SummaryHelper.setSummaryCount(json.activities.quiz, dataVal =>{
dispatch(summaryCountAllDispatch(dataVal))
});
Expand Down
14 changes: 7 additions & 7 deletions app/config/quiz/topic2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,24 +1268,24 @@ export const listening = [
"english":"vietnam",
"answerOption":[
{
"id":"tp2_l_4",
"id":"tp2_l_3",
"type":"listening",
"moji":"日本"
"moji":"1月 26日"
},
{
"id":"tp2_l_2",
"type":"listening",
"moji":"フィリピン"
"moji":"2月 1日"
},
{
"id":"tp2_l_3",
"id":"tp2_l_1",
"type":"listening",
"moji":"ベトナム"
"moji":"2月 18日"
},
{
"id":"tp2_l_1",
"id":"tp2_l_4",
"type":"listening",
"moji":"タイ"
"moji":"8月 18日"
}
],
"audio":"t2_listening_3.mp3"
Expand Down
20 changes: 16 additions & 4 deletions app/screens/Quiz/quizFlash.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ import {
listening: 3
}

// this.testItemCount = {
// vocabulary: 1,
// kanji: 1,
// grammar: 1,
// reading: 1,
// listening: 1
// }
this.shortType = {
'v' : 'vocabulary',
'g' : 'grammar',
Expand Down Expand Up @@ -848,12 +855,17 @@ import {
};

setScore(){
var quizSizes = 0;

var quizSizes = this.allQuestion.length;
if(this.initialParams.isTopicTest){
quizSizes = this.allQuestion.length;

return Helper.countScore(this.studyRecord,quizSizes);
}
return Helper.countScore(this.studyRecord,quizSizes);
else{
return Helper.countScore(this.studyRecord,quizSizes,true);
}


}

goNextQuestion() {
Expand Down
40 changes: 35 additions & 5 deletions app/screens/Study/topiclist.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { strings } from '../../config/localization';
import { ImageData } from '../../config/image_list';
import { StudyList } from '../../config/studyList';

import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as Actions from '../../actions/summary';
class TopicListScreen extends Component {

static navigationOptions = ({ navigation }) =>{
Expand All @@ -33,18 +36,24 @@ class TopicListScreen extends Component {
title:"TOPIC10_TITLE",
img: "",
index: "",
nextTopic: "",
};
}

componentDidMount() {
const { navigation } = this.props;
this.setState({

params = {
title: navigation.getParam('title', null),
img: navigation.getParam('img', null),
type: navigation.getParam('type', null),
index: navigation.getParam('index', null),
});
console.log(navigation.getParam('index', null));
index: navigation.getParam('index', null),
}

params.nextTopic = StudyList[params.index + 1];

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

Expand Down Expand Up @@ -80,6 +89,7 @@ navigateToLearn=(type, categoryId)=>{
navigateToNextTopic=()=>{
var item = StudyList[this.state.index + 1];
item['index'] = this.state.index + 1;
console.log(this.props.lock,'-weee',item);

const resetAction = NavigationActions.reset({
index: 1,
Expand All @@ -89,6 +99,7 @@ navigateToLearn=(type, categoryId)=>{
]
});


this.props.navigation.dispatch(resetAction);


Expand Down Expand Up @@ -139,4 +150,23 @@ navigateToLearn=(type, categoryId)=>{
const styles = require('../../styles/style');
const study = require('../../styles/study');

export default TopicListScreen;
// The function takes data from the app current state,
// and insert/links it into the props of our component.
// This function makes Redux know that this component needs to be passed a piece of the state
function mapStateToProps(state, props) {

return {
lock : state.summary.lock
}
}


// Doing this merges our actions into the component’s props,
// while wrapping them in dispatch() so that they immediately dispatch an Action.
// Just by doing this, we will have access to the actions defined in out actions file (action/home.js)
function mapDispatchToProps(dispatch) {
return bindActionCreators(Actions, dispatch);
}

//Connect everything
export default connect(mapStateToProps, mapDispatchToProps)(TopicListScreen);
4 changes: 1 addition & 3 deletions app/styles/study.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ module.exports = StyleSheet.create({
nextTopic: {
height: 60,
width : '98%',
backgroundColor: '#cccccc',
backgroundColor: primaryColor,
justifyContent: 'center',
alignItems: 'center',
borderColor: '#cccccc',
borderWidth: 1,
borderRadius: 5,
},
buttonTopicNextText:{
Expand Down

0 comments on commit dca1936

Please sign in to comment.