From 5073d3a1c2b767c000b44a70acaec4326fe842c3 Mon Sep 17 00:00:00 2001 From: Dslak Date: Sun, 20 Oct 2019 19:18:43 +0200 Subject: [PATCH 1/4] add exam questions filter --- vds-app/App/components/Results.js | 19 +++- vds-app/App/components/Variables.js | 12 +++ vds-app/App/index.js | 12 +++ vds-app/App/screens/Exam.js | 133 ++++++++++++++++++++++++++++ vds-app/App/screens/QuizIndex.js | 35 +++++++- 5 files changed, 204 insertions(+), 7 deletions(-) create mode 100644 vds-app/App/screens/Exam.js diff --git a/vds-app/App/components/Results.js b/vds-app/App/components/Results.js index 6e95233..30c8053 100644 --- a/vds-app/App/components/Results.js +++ b/vds-app/App/components/Results.js @@ -25,7 +25,7 @@ const styles = StyleSheet.create({ alignItems: "center", justifyContent: "center" }, - boxLooser: { + boxWrong: { backgroundColor: colors.red_alpha, width: screen.width / 1.1, height: screen.height / 2, @@ -35,6 +35,16 @@ const styles = StyleSheet.create({ alignItems: "center", justifyContent: "center" }, + boxUnsafe: { + backgroundColor: colors.orange, + width: screen.width / 1.1, + height: screen.height / 2, + borderRadius: 5, + borderColor: colors.orange, + borderWidth: 5, + alignItems: "center", + justifyContent: "center" + }, text: { color: colors.white, fontSize: 25, @@ -52,6 +62,9 @@ const styles = StyleSheet.create({ }, wrong: { color: colors.red + }, + unsafe: { + color: colors.yellow } }) @@ -60,8 +73,8 @@ export const Results = ({ correct, wrong, visible }) => { const total = wrong+correct const percentage = (100/total) * correct - const boxStyle = percentage > 80 ? styles.box : styles.boxLooser - const percentStyle = percentage > 80 ? styles.correct : styles.wrong + const boxStyle = percentage >= 80 ? percentage >= 85 ? styles.box : styles.boxUnsafe : styles.boxWrong + const percentStyle = percentage >= 80 ? percentage >= 85 ? styles.correct : styles.unsafe : styles.wrong return ( diff --git a/vds-app/App/components/Variables.js b/vds-app/App/components/Variables.js index a3200ab..87f951a 100644 --- a/vds-app/App/components/Variables.js +++ b/vds-app/App/components/Variables.js @@ -29,3 +29,15 @@ export const texts = { physiopathology: "Fisiopatologia del volo", piloting_techniques: "Tecniche di pilotaggio" } + +export const examScheme = [ + {section: "aerodynamics", questions: 8, points: 3}, + {section: "firstAid", questions: 1, points: 2}, + {section: "flightSafety", questions: 3, points: 4}, + {section: "instruments", questions: 1, points: 2}, + {section: "legislation", questions: 4, points: 3}, + {section: "materials", questions: 1, points: 2}, + {section: "meteorology", questions: 6, points: 4}, + {section: "physiopathology", questions: 1, points: 2}, + {section: "pilotingTechniques", questions: 5, points: 4} +] diff --git a/vds-app/App/index.js b/vds-app/App/index.js index eff7a1a..3734f9f 100644 --- a/vds-app/App/index.js +++ b/vds-app/App/index.js @@ -2,6 +2,7 @@ import { createStackNavigator, createAppContainer } from "react-navigation" import QuizIndex from "./screens/QuizIndex" import Quiz from "./screens/Quiz" +import Exam from "./screens/Exam" import { colors, texts} from "./components/Variables" const MainStack = createStackNavigator({ @@ -26,6 +27,17 @@ const MainStack = createStackNavigator({ borderBottomColor: navigation.getParam("color") } }) + }, + Exam: { + screen: Exam, + navigationOptions: ({ navigation }) => ({ + headerTitle: navigation.getParam("title"), + headerTintColor: colors.white, + headerStyle: { + backgroundColor: navigation.getParam("color"), + borderBottomColor: navigation.getParam("color") + } + }) } }) diff --git a/vds-app/App/screens/Exam.js b/vds-app/App/screens/Exam.js new file mode 100644 index 0000000..ada9393 --- /dev/null +++ b/vds-app/App/screens/Exam.js @@ -0,0 +1,133 @@ +import React from "react" +import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView } from "react-native" + +import { Button, ButtonContainer } from "../components/Button" +import { Alert } from "../components/Alert" +import { Results } from "../components/Results" +import { colors } from "../components/Variables" + +const styles = StyleSheet.create({ + container: { + backgroundColor: colors.blue, + flex: 1, + paddingHorizontal: 20 + }, + text: { + color: colors.white, + fontSize: 20, + textAlign: "center", + fontWeight: "600", + paddingVertical: 20, + marginTop: 20, + }, + safearea: { + flex: 1, + marginTop: 20, + justifyContent: "space-between" + } +}) + +class Exam extends React.Component { + + state = { + correctCount: 0, + wrongCount: 0, + totalCount: this.props.navigation.getParam("questions", []).length, + availableIds: this.props.navigation.getParam("questions", []).map(a => a.id), + activeQuestionId: this.props.navigation.getParam("questions", [])[ + Math.floor(Math.random() * this.props.navigation.getParam("questions", []).length) + ].id, + answered: false, + answerCorrect: false, + results: false + } + + answer = correct => { + this.setState( + state => { + const nextState = { answered: true } + + if (correct) { + nextState.correctCount = state.correctCount + 1 + nextState.answerCorrect = true + } else { + nextState.wrongCount = state.wrongCount + 1 + nextState.answerCorrect = false + } + + return nextState + }, + () => { + setTimeout(() => this.nextQuestion(), 750) + } + ) + } + + nextQuestion = () => { + this.setState( (state) => { + const updatedIndexes = state.availableIds.filter( item => item != state.activeQuestionId) + const nextId = updatedIndexes[Math.floor(Math.random() * updatedIndexes.length)] + let resultsShow = false + + if (!updatedIndexes.length) { + resultsShow = true + setTimeout( () => { + this.props.navigation.popToTop() + }, 5000) + } + + return { + //totalCount: updatedIndexes.length, + availableIds: updatedIndexes, + activeQuestionId: nextId, + answered: false, + results: resultsShow + } + }) + } + + render() { + const questions = this.props.navigation.getParam("questions", []) + const question = questions.filter(item => item.id == this.state.activeQuestionId)[0] || questions[0] + + return ( + + + + + {question.question} + + + {question.answers.map(answer => ( +