diff --git a/vds-app/App/components/Button.js b/vds-app/App/components/Button.js index d29bb36..f8bed21 100644 --- a/vds-app/App/components/Button.js +++ b/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", diff --git a/vds-app/App/components/Variables.js b/vds-app/App/components/Variables.js index f581e12..b93e3f9 100644 --- a/vds-app/App/components/Variables.js +++ b/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", diff --git a/vds-app/App/screens/Exam.js b/vds-app/App/screens/Exam.js index ab14cd8..9b56ca5 100644 --- a/vds-app/App/screens/Exam.js +++ b/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 }, diff --git a/vds-app/App/screens/Quiz.js b/vds-app/App/screens/Quiz.js index e033e44..b56e89c 100644 --- a/vds-app/App/screens/Quiz.js +++ b/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, diff --git a/vds-app/App/screens/QuizIndex.js b/vds-app/App/screens/QuizIndex.js index 0ad600c..55c9a76 100644 --- a/vds-app/App/screens/QuizIndex.js +++ b/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 { + + + + this.props.navigation.navigate("Quiz", { + title: "TEST", + questions: testQuestions, + color: colors.blue + })}/> + this.props.navigation.navigate("Quiz", { title: texts.aerodynamics, diff --git a/vds-app/App/screens/Recap.js b/vds-app/App/screens/Recap.js index 26d4168..64dd9ef 100644 --- a/vds-app/App/screens/Recap.js +++ b/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) => ( {question.id} - {question.text} + {question.question} {question.answers.map( (answer, index) => ( diff --git a/vds-app/App/screens/RecapTrueFalse.js b/vds-app/App/screens/RecapTrueFalse.js index 1d388ad..5b7b720 100644 --- a/vds-app/App/screens/RecapTrueFalse.js +++ b/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) => ( {question.id} - {question.text} + {question.question} {question.answers.map( (answer, index) => { diff --git a/vds-app/App/screens/Results.js b/vds-app/App/screens/Results.js index 2a47526..51f9f23 100644 --- a/vds-app/App/screens/Results.js +++ b/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 ( @@ -182,9 +197,13 @@ class Results extends React.Component { {`${texts.percentage}: ${Math.round(percentage)}%`} - - {`${texts.points}: ${currentResults.points}/${currentResults.totalPoints}`} - + { + currentResults.points ? ( + + {`${texts.points}: ${currentResults.points}/${currentResults.totalPoints}`} + + ) : null + } {currentResults.isExam ? diff --git a/vds-app/App/screens/Splash.js b/vds-app/App/screens/Splash.js index 54e9dd2..c4187dd 100644 --- a/vds-app/App/screens/Splash.js +++ b/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 ? ( +