From 6a3c5545efadeda6ce2e6fbeddc7b937e59410e7 Mon Sep 17 00:00:00 2001 From: Carmine De Rosa Date: Thu, 29 Oct 2020 15:04:14 +0100 Subject: [PATCH] reset filtered exam questions on back --- vds-app/App/screens/Recap.js | 37 ++++++++++++++++----------- vds-app/App/screens/Results.js | 34 ++++++++++++++----------- vds-app/App/screens/Setup.js | 46 ++++++++++++++++++++++++++++++++-- vds-app/App/screens/Splash.js | 19 ++++++++++---- 4 files changed, 100 insertions(+), 36 deletions(-) diff --git a/vds-app/App/screens/Recap.js b/vds-app/App/screens/Recap.js index 47d5449..c65e68c 100644 --- a/vds-app/App/screens/Recap.js +++ b/vds-app/App/screens/Recap.js @@ -127,21 +127,28 @@ class Recap extends React.Component { handleBackButton = () => { - const tmpQuestions = [] - examScheme.forEach( (elem) => { - let currentSection = allQuestions[elem.section] - for(let i=0; i index != currentIndex) - } - }) - - this.props.navigation.navigate("Splash", { - examQuestions: tmpQuestions, - storeWrongAnswers: this.state.storeWrongAnswers - }) - return true + + let tmpQuestions = [] + AsyncStorage.getItem('setupData').then((value) => { + let setupData = JSON.parse(value) + + examScheme.forEach( (elem) => { + let currentSection = setupData.excludeDelta ? allQuestions[elem.section].filter(item => !item.delta) : allQuestions[elem.section] + for(let i=0; i index != currentIndex) + } + }) + + this.props.navigation.navigate("Splash", { + examQuestions: tmpQuestions, + storeWrongAnswers: this.state.storeWrongAnswers + }) + + return true + + }).done() } render() { diff --git a/vds-app/App/screens/Results.js b/vds-app/App/screens/Results.js index d2bd33a..9b1a695 100644 --- a/vds-app/App/screens/Results.js +++ b/vds-app/App/screens/Results.js @@ -148,21 +148,27 @@ class Results extends React.Component { handleBackButton = () => { - const tmpQuestions = [] - examScheme.forEach( (elem) => { - let currentSection = allQuestions[elem.section] - for(let i=0; i index != currentIndex) - } - }) + let tmpQuestions = [] + AsyncStorage.getItem('setupData').then((value) => { + let setupData = JSON.parse(value) - this.props.navigation.navigate("Splash", { - examQuestions: tmpQuestions, - storeWrongAnswers: this.state.storeWrongAnswers - }) - return true + examScheme.forEach( (elem) => { + let currentSection = setupData.excludeDelta ? allQuestions[elem.section].filter(item => !item.delta) : allQuestions[elem.section] + for(let i=0; i index != currentIndex) + } + }) + + this.props.navigation.navigate("Splash", { + examQuestions: tmpQuestions, + storeWrongAnswers: this.state.storeWrongAnswers + }) + + return true + + }).done() } diff --git a/vds-app/App/screens/Setup.js b/vds-app/App/screens/Setup.js index 118ec61..95f3d54 100644 --- a/vds-app/App/screens/Setup.js +++ b/vds-app/App/screens/Setup.js @@ -4,6 +4,28 @@ import { View, ScrollView, StyleSheet, StatusBar, Text, CheckBox, SafeAreaView, import { Button, ButtonContainer } from "../components/Button" import { colors, texts, examScheme, resultsScheme} from "../components/Variables" +import aerodynamicsQuestions from "../data/aerodynamics" +import firstAidQuestions from "../data/firstAid" +import flightSafetyQuestions from "../data/flightSafety" +import instrumentsQuestions from "../data/instruments" +import legislationQuestions from "../data/legislation" +import materialsQuestions from "../data/materials" +import meteorologyQuestions from "../data/meteorology" +import physiopathologyQuestions from "../data/physiopathology" +import pilotingTechniquesQuestions from "../data/pilotingTechniques" + +const allQuestions = { + aerodynamics: aerodynamicsQuestions, + firstAid: firstAidQuestions, + flightSafety: flightSafetyQuestions, + instruments: instrumentsQuestions, + legislation: legislationQuestions, + materials: materialsQuestions, + meteorology: meteorologyQuestions, + physiopathology: physiopathologyQuestions, + pilotingTechniques: pilotingTechniquesQuestions +} + const bgImage = require("../assets/bg.jpg") const screen = Dimensions.get("window") @@ -158,8 +180,28 @@ class Setup extends React.Component { } handleBackButton = () => { - this.props.navigation.navigate("Splash") - return true + + let tmpQuestions = [] + AsyncStorage.getItem('setupData').then((value) => { + let setupData = JSON.parse(value) + + examScheme.forEach( (elem) => { + let currentSection = setupData.excludeDelta ? allQuestions[elem.section].filter(item => !item.delta) : allQuestions[elem.section] + for(let i=0; i index != currentIndex) + } + }) + + this.props.navigation.navigate("Splash", { + examQuestions: tmpQuestions + }) + + return true + + }).done() + } changeSetup = (item) => { diff --git a/vds-app/App/screens/Splash.js b/vds-app/App/screens/Splash.js index a8df77c..39a4f02 100644 --- a/vds-app/App/screens/Splash.js +++ b/vds-app/App/screens/Splash.js @@ -83,7 +83,8 @@ class Splash extends React.Component { state = { bannerExpanded: true, timer: maxTime, - storeWrongAnswers: this.props.navigation.getParam("storeWrongAnswers", []) || [] + storeWrongAnswers: this.props.navigation.getParam("storeWrongAnswers", []) || [], + setupData: {} } bannerError = (e) => { @@ -97,12 +98,20 @@ class Splash extends React.Component { AsyncStorage.setItem('storeWrongAnswers', JSON.stringify([])) } - this.setState( (state) => { - return { - storeWrongAnswers: value ? JSON.parse(value) : [] + AsyncStorage.getItem('setupData').then((setup) => { + if(!setup) { + AsyncStorage.setItem('setupData', JSON.stringify({})) } - }) + this.setState( (state) => { + return { + storeWrongAnswers: value ? JSON.parse(value) : [], + setupData: setup ? JSON.parse(setup) : {} + } + }) + }).done() }).done() + + } componentWillUnmount() {