Browse Source

add wrong questions recap

feature/upgrade_sdk
Carmine De Rosa 5 years ago
parent
commit
d622e324aa
  1. 2
      vds-app/App/components/Button.js
  2. 1
      vds-app/App/components/Variables.js
  3. 5
      vds-app/App/screens/Exam.js
  4. 3
      vds-app/App/screens/Quiz.js
  5. 23
      vds-app/App/screens/QuizIndex.js
  6. 21
      vds-app/App/screens/Recap.js
  7. 7
      vds-app/App/screens/RecapTrueFalse.js
  8. 37
      vds-app/App/screens/Results.js
  9. 42
      vds-app/App/screens/Splash.js
  10. 2
      vds-app/App/screens/TrueFalse.js

2
vds-app/App/components/Button.js

@ -10,7 +10,7 @@ const styles = StyleSheet.create({
borderWidth: 4,
borderColor: 'transparent',
borderRadius: 10,
paddingHorizontal: 20,
//paddingHorizontal: 20,
paddingVertical: 15,
alignItems: "center",
justifyContent: "center",

1
vds-app/App/components/Variables.js

@ -23,6 +23,7 @@ export const colors = {
export const texts = {
quizzes: "Seleziona un argomento",
section_quizzes: "Quiz per argomento",
wrong_review: "Rivedi domande sbagliate",
section_quizzes_subtitle: "Esercitati su argomenti specifici",
exam: "Simulazione esame",
exam_simulation: "30 domande in 30min",

5
vds-app/App/screens/Exam.js

@ -115,8 +115,6 @@ class Exam extends React.Component {
}
})
//tmpQuestions.forEach( (e) => { console.log(e.id) })
this.props.navigation.navigate("Splash", {
examQuestions: tmpQuestions
})
@ -151,13 +149,12 @@ class Exam extends React.Component {
nextState.answerCorrect = false
nextState.wrongAnswers = state.wrongAnswers
nextState.wrongAnswers.push(
{ text: question.question,
{ question: question.question,
id: question.id,
clicked: id,
answers: question.answers
}
)
//console.log(state.wrongAnswers)
}
return nextState
},

3
vds-app/App/screens/Quiz.js

@ -109,7 +109,7 @@ class Quiz extends React.Component {
nextState.answerCorrect = false,
nextState.wrongAnswers = state.wrongAnswers
nextState.wrongAnswers.push(
{ text: question.question,
{ question: question.question,
id: question.id,
clicked: id,
answers: question.answers
@ -135,6 +135,7 @@ class Quiz extends React.Component {
this.props.navigation.navigate("Results", {
results: {
isExam: false,
isWrong: this.props.navigation.getParam("isWrong"),
total: this.state.totalCount,
correct: this.state.correctCount,
wrong: this.state.wrongCount,

23
vds-app/App/screens/QuizIndex.js

@ -1,5 +1,5 @@
import React from "react"
import { View, ScrollView, StatusBar, BackHandler, StyleSheet, Dimensions, ImageBackground } from "react-native"
import { View, ScrollView, StatusBar, BackHandler, StyleSheet, Dimensions, ImageBackground, AsyncStorage } from "react-native"
import aerodynamicsQuestions from "../data/aerodynamics"
import firstAidQuestions from "../data/firstAid"
@ -39,8 +39,20 @@ const styles = StyleSheet.create({
class QuizIndex extends React.Component {
state = {
storeWrongAnswers: []
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton)
AsyncStorage.getItem('storeWrongAnswers').then((value) => {
//console.log('storeWrongAnswers: ', JSON.parse(value))
this.setState( (state) => {
return {
storeWrongAnswers: JSON.parse(value)
}
})
}).done()
}
componentWillUnmount() {
@ -57,6 +69,15 @@ class QuizIndex extends React.Component {
<ImageBackground source={bgImage} style={styles.bg} resizeMode="cover">
<ScrollView >
<View style={{marginVertical: 60}}>
<RowItem name="TEST" textColor={colors.white} onPress={()=>
this.props.navigation.navigate("Quiz", {
title: "TEST",
questions: testQuestions,
color: colors.blue
})}/>
<RowItem name={texts.aerodynamics} subtitle={aerodynamicsQuestions.length} textColor={colors.white} onPress={()=>
this.props.navigation.navigate("Quiz", {
title: texts.aerodynamics,

21
vds-app/App/screens/Recap.js

@ -1,5 +1,5 @@
import React from "react"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, ImageBackground, BackHandler} from "react-native"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, ImageBackground, BackHandler, AsyncStorage} from "react-native"
import { AdMobBanner } from "expo-ads-admob"
import { Button, ButtonContainer } from "../components/Button"
@ -105,8 +105,20 @@ const styles = StyleSheet.create({
class Recap extends React.Component {
state = {
storeWrongAnswers: []
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton)
AsyncStorage.getItem('storeWrongAnswers').then((value) => {
//console.log('storeWrongAnswers: ', JSON.parse(value))
this.setState( (state) => {
return {
storeWrongAnswers: JSON.parse(value)
}
})
}).done()
}
componentWillUnmount() {
@ -125,10 +137,9 @@ class Recap extends React.Component {
}
})
//tmpQuestions.forEach( (e) => { console.log(e.id) })
this.props.navigation.navigate("Splash", {
examQuestions: tmpQuestions
examQuestions: tmpQuestions,
storeWrongAnswers: this.state.storeWrongAnswers
})
return true
}
@ -150,7 +161,7 @@ class Recap extends React.Component {
{questions.map( (question, index) => (
<View style={styles.box} key={question.id}>
<Text style={styles.textCode}>{question.id}</Text>
<Text style={styles.text}>{question.text}</Text>
<Text style={styles.text}>{question.question}</Text>
<ButtonContainer>
{question.answers.map( (answer, index) => (

7
vds-app/App/screens/RecapTrueFalse.js

@ -1,5 +1,5 @@
import React from "react"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, ImageBackground, BackHandler} from "react-native"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, ImageBackground, BackHandler, AsyncStorage} from "react-native"
import { AdMobBanner } from "expo-ads-admob"
import { Button, ButtonContainer } from "../components/Button"
@ -107,6 +107,9 @@ class RecapTrueFalse extends React.Component {
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton)
AsyncStorage.getItem('storeWrongAnswers').then((value) => {
console.log(value)
}).done()
}
componentWillUnmount() {
@ -154,7 +157,7 @@ class RecapTrueFalse extends React.Component {
{questions.map( (question, index) => (
<View style={styles.box} key={question.id}>
<Text style={styles.textCode}>{question.id}</Text>
<Text style={styles.text}>{question.text}</Text>
<Text style={styles.text}>{question.question}</Text>
<ButtonContainer>
{question.answers.map( (answer, index) => {

37
vds-app/App/screens/Results.js

@ -1,5 +1,5 @@
import React from "react"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, BackHandler} from "react-native"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, BackHandler, AsyncStorage} from "react-native"
import { Button, ButtonContainer } from "../components/Button"
import { colors, texts, examScheme } from "../components/Variables"
@ -119,11 +119,27 @@ class Results extends React.Component {
state = {
bannerExpanded: true,
timer: maxTime
timer: maxTime,
storeWrongAnswers: []
}
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton)
AsyncStorage.getItem('storeWrongAnswers').then( (value) => {
const currentResults = this.props.navigation.getParam("results")
const wrongAnswers = currentResults.wrongAnswers || []
const stored = JSON.parse(value) || []
const result = currentResults.isWrong ? wrongAnswers : Object.assign([], wrongAnswers, stored);
AsyncStorage.setItem('storeWrongAnswers', JSON.stringify(result))
this.setState( (state) => {
return {
storeWrongAnswers: result
}
})
}).done()
}
componentWillUnmount() {
@ -142,14 +158,14 @@ class Results extends React.Component {
}
})
//tmpQuestions.forEach( (e) => { console.log(e.id) })
this.props.navigation.navigate("Splash", {
examQuestions: tmpQuestions
examQuestions: tmpQuestions,
storeWrongAnswers: this.state.storeWrongAnswers
})
return true
}
render() {
const currentResults = this.props.navigation.getParam("results")
@ -163,7 +179,6 @@ class Results extends React.Component {
boxStyle = percentage >= 80 ? percentage >= 85 ? styles.boxCorrect : styles.boxUnsafe : styles.boxWrong
}
//console.log(currentResults)
return (
<View style={styles.container} >
@ -182,9 +197,13 @@ class Results extends React.Component {
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.percentage}: ${Math.round(percentage)}%`}</Text>
</Text>
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.points}: ${currentResults.points}/${currentResults.totalPoints}`}</Text>
</Text>
{
currentResults.points ? (
<Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.points}: ${currentResults.points}/${currentResults.totalPoints}`}</Text>
</Text>
) : null
}
{currentResults.isExam ?
<Text style={[styles.textSmall, resultStyle]}>

42
vds-app/App/screens/Splash.js

@ -1,5 +1,5 @@
import React from "react"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, Alert, BackHandler } from "react-native"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, Alert, BackHandler, AsyncStorage } from "react-native"
import { AdMobBanner } from "expo-ads-admob"
import { Button, ButtonContainer } from "../components/Button"
@ -81,7 +81,8 @@ class Splash extends React.Component {
state = {
bannerExpanded: true,
timer: maxTime
timer: maxTime,
storeWrongAnswers: this.props.navigation.getParam("storeWrongAnswers", []) || []
}
bannerError = (e) => {
@ -90,6 +91,17 @@ class Splash extends React.Component {
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButton)
AsyncStorage.getItem('storeWrongAnswers').then( (value) => {
if(!value) {
AsyncStorage.setItem('storeWrongAnswers', JSON.stringify([]))
}
this.setState( (state) => {
return {
storeWrongAnswers: value ? JSON.parse(value) : []
}
})
}).done()
}
componentWillUnmount() {
@ -111,6 +123,10 @@ class Splash extends React.Component {
render() {
const storeWrongAnswers = this.props.navigation.getParam("storeWrongAnswers") || this.state.storeWrongAnswers
//console.log(storeWrongAnswers.length)
if(this.state.timer==maxTime) {
interval = setInterval( () => {
this.setState( (state) => {
@ -155,6 +171,28 @@ class Splash extends React.Component {
color: colors.white_alpha
})}
/>
{
storeWrongAnswers.length ? (
<Button
text={texts.wrong_review}
subtitle={`(${storeWrongAnswers.length})`}
isBig={false}
hasBg={true}
noPadding={true}
hasShadow={true}
color={colors.white_alpha}
onPress={() =>
this.props.navigation.navigate("Quiz", {
title: texts.wrong_review,
questions: storeWrongAnswers,
isWrong: true,
color: colors.blue
})}
/>
) : null
}
<Button
text={texts.exam}
subtitle={`(${texts.exam_simulation})`}

2
vds-app/App/screens/TrueFalse.js

@ -160,7 +160,7 @@ class Quiz extends React.Component {
nextState.wrongCount = state.wrongCount + 1
nextState.wrongAnswers = state.wrongAnswers
nextState.wrongAnswers.push(
{ text: question.question,
{ question: question.question,
id: question.id,
clicked: question.answers[state.activeAnswerId].id,
answers: question.answers

Loading…
Cancel
Save