Browse Source

simulation alert

master
Dslak 6 years ago
parent
commit
47568f9a98
  1. 34
      vds-app/App/components/Results.js
  2. 7
      vds-app/App/components/RowItem.js
  3. 2
      vds-app/App/components/Variables.js
  4. 15
      vds-app/App/screens/Exam.js
  5. 1
      vds-app/App/screens/Quiz.js
  6. 27
      vds-app/App/screens/QuizIndex.js

34
vds-app/App/components/Results.js

@ -18,8 +18,8 @@ const styles = StyleSheet.create({
box: { box: {
backgroundColor: colors.green_alpha, backgroundColor: colors.green_alpha,
width: screen.width / 1.1, width: screen.width / 1.1,
height: screen.height / 2,
borderRadius: 5,
height: 320,
borderRadius: 15,
borderColor: colors.white_alpha, borderColor: colors.white_alpha,
borderWidth: 5, borderWidth: 5,
alignItems: "center", alignItems: "center",
@ -28,8 +28,8 @@ const styles = StyleSheet.create({
boxWrong: { boxWrong: {
backgroundColor: colors.red_alpha, backgroundColor: colors.red_alpha,
width: screen.width / 1.1, width: screen.width / 1.1,
height: screen.height / 2,
borderRadius: 5,
height: 320,
borderRadius: 15,
borderColor: colors.white_alpha, borderColor: colors.white_alpha,
borderWidth: 5, borderWidth: 5,
alignItems: "center", alignItems: "center",
@ -38,9 +38,9 @@ const styles = StyleSheet.create({
boxUnsafe: { boxUnsafe: {
backgroundColor: colors.orange, backgroundColor: colors.orange,
width: screen.width / 1.1, width: screen.width / 1.1,
height: screen.height / 2,
borderRadius: 5,
borderColor: colors.orange,
height: 320,
borderRadius: 15,
borderColor: colors.white_alpha,
borderWidth: 5, borderWidth: 5,
alignItems: "center", alignItems: "center",
justifyContent: "center" justifyContent: "center"
@ -51,7 +51,7 @@ const styles = StyleSheet.create({
textAlign: "center", textAlign: "center",
letterSpacing: -0.02, letterSpacing: -0.02,
fontWeight: "500", fontWeight: "500",
lineHeight: 90
lineHeight: 50
}, },
textLabel: { textLabel: {
paddingHorizontal: 20, paddingHorizontal: 20,
@ -68,10 +68,9 @@ const styles = StyleSheet.create({
} }
}) })
export const Results = ({ correct, wrong, visible }) => {
export const Results = ({ total, correct, wrong, visible }) => {
if (!visible) return null if (!visible) return null
const total = wrong+correct
const percentage = total ? (100/total) * correct : 0 const percentage = total ? (100/total) * correct : 0
const boxStyle = percentage >= 80 ? percentage >= 85 ? styles.box : styles.boxUnsafe : styles.boxWrong const boxStyle = percentage >= 80 ? percentage >= 85 ? styles.box : styles.boxUnsafe : styles.boxWrong
const percentStyle = percentage >= 80 ? percentage >= 85 ? styles.correct : styles.unsafe : styles.wrong const percentStyle = percentage >= 80 ? percentage >= 85 ? styles.correct : styles.unsafe : styles.wrong
@ -80,22 +79,13 @@ export const Results = ({ correct, wrong, visible }) => {
<View style={styles.container}> <View style={styles.container}>
<View style={boxStyle}> <View style={boxStyle}>
<Text style={styles.text}> <Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.corrects}: `}</Text>
<Text >
{`${correct}`}
</Text>
<Text style={styles.textLabel}>{`${texts.corrects}: ${correct}`}</Text>
</Text> </Text>
<Text style={styles.text}> <Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.wrongs}: `}</Text>
<Text>
{`${wrong}`}
</Text>
<Text style={styles.textLabel}>{`${texts.wrongs}: ${wrong}`}</Text>
</Text> </Text>
<Text style={styles.text}> <Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.percentage}: `}</Text>
<Text >
{`${Math.round(percentage)}%`}
</Text>
<Text style={styles.textLabel}>{`${texts.percentage}: ${Math.round(percentage)}%`}</Text>
</Text> </Text>
</View> </View>
</View> </View>

7
vds-app/App/components/RowItem.js

@ -7,8 +7,7 @@ const styles = StyleSheet.create({
paddingHorizontal: 15, paddingHorizontal: 15,
paddingVertical: 20, paddingVertical: 20,
backgroundColor: colors.blue, backgroundColor: colors.blue,
borderBottomColor: colors.dark_blue,
borderBottomWidth: 1
marginBottom: 1
}, },
text: { text: {
fontSize: 18, fontSize: 18,
@ -17,10 +16,10 @@ const styles = StyleSheet.create({
} }
}) })
export const RowItem = ({ onPress = () => {}, name, color }) => (
export const RowItem = ({ onPress = () => {}, name, color, textColor }) => (
<TouchableOpacity onPress={onPress} activeOpacity={0.8}> <TouchableOpacity onPress={onPress} activeOpacity={0.8}>
<View style={[styles.row, { backgroundColor: color }]}> <View style={[styles.row, { backgroundColor: color }]}>
<Text style={styles.text}>{name}</Text>
<Text style={[styles.text, { color: textColor }]}>{name}</Text>
</View> </View>
</TouchableOpacity> </TouchableOpacity>
) )

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

@ -15,7 +15,7 @@ export const colors = {
export const texts = { export const texts = {
quizzes: "Seleziona un quiz", quizzes: "Seleziona un quiz",
exam: "Simulazione esame",
exam: "Simulazione esame (30 domande in 30min)",
corrects: "Corrette", corrects: "Corrette",
wrongs: "Sbagliate", wrongs: "Sbagliate",
percentage: "Percentuale", percentage: "Percentuale",

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

@ -36,7 +36,7 @@ const styles = StyleSheet.create({
}) })
let interval = null let interval = null
const maxTime = 10
const maxTime = 10 // 1800
class Exam extends React.Component { class Exam extends React.Component {
@ -51,7 +51,7 @@ class Exam extends React.Component {
answered: false, answered: false,
answerCorrect: false, answerCorrect: false,
results: false, results: false,
timer: 0
timer: maxTime
} }
answer = correct => { answer = correct => {
@ -79,7 +79,7 @@ class Exam extends React.Component {
this.setState( (state) => { this.setState( (state) => {
const updatedIndexes = state.availableIds.filter( item => item != state.activeQuestionId) const updatedIndexes = state.availableIds.filter( item => item != state.activeQuestionId)
const nextId = updatedIndexes[Math.floor(Math.random() * updatedIndexes.length)] const nextId = updatedIndexes[Math.floor(Math.random() * updatedIndexes.length)]
let resultsShow = this.state.timer >= maxTime-1 || false
let resultsShow = this.state.timer <= 1 || false
if (!updatedIndexes.length) { if (!updatedIndexes.length) {
resultsShow = true resultsShow = true
@ -101,18 +101,18 @@ class Exam extends React.Component {
const questions = this.props.navigation.getParam("questions", []) const questions = this.props.navigation.getParam("questions", [])
const question = questions.filter(item => item.id == this.state.activeQuestionId)[0] || questions[0] const question = questions.filter(item => item.id == this.state.activeQuestionId)[0] || questions[0]
if(this.state.timer==0) {
if(this.state.timer==maxTime) {
interval = setInterval( () => { interval = setInterval( () => {
this.setState( (state) => { this.setState( (state) => {
return { return {
timer: this.state.timer+1,
results: this.state.timer >= maxTime-1 || false
timer: this.state.timer-1,
results: this.state.timer <= 1 || false
} }
}) })
}, 1000) }, 1000)
} }
if(this.state.timer >= maxTime) {
if(this.state.timer < 1) {
clearInterval(interval) clearInterval(interval)
setTimeout( () => { setTimeout( () => {
this.props.navigation.popToTop() this.props.navigation.popToTop()
@ -151,6 +151,7 @@ class Exam extends React.Component {
visible={this.state.answered} visible={this.state.answered}
/> />
<Results <Results
total={this.state.totalCount}
correct={this.state.correctCount} correct={this.state.correctCount}
wrong={this.state.wrongCount} wrong={this.state.wrongCount}
visible={this.state.results} visible={this.state.results}

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

@ -121,6 +121,7 @@ class Quiz extends React.Component {
visible={this.state.answered} visible={this.state.answered}
/> />
<Results <Results
total={this.state.totalCount}
correct={this.state.correctCount} correct={this.state.correctCount}
wrong={this.state.wrongCount} wrong={this.state.wrongCount}
visible={this.state.results} visible={this.state.results}

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

@ -19,82 +19,75 @@ import { examQuestions } from "../components/ExamQuestions"
export default ({ navigation }) => ( export default ({ navigation }) => (
<ScrollView style={[{ backgroundColor: colors.dark_blue }]}> <ScrollView style={[{ backgroundColor: colors.dark_blue }]}>
<StatusBar barStyle="dark-content" /> <StatusBar barStyle="dark-content" />
<RowItem name={texts.aerodynamics} color={colors.blue} onPress={() =>
<RowItem name={texts.aerodynamics} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.aerodynamics, title: texts.aerodynamics,
questions: aerodynamicsQuestions, questions: aerodynamicsQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.first_aid} color={colors.blue} onPress={() =>
<RowItem name={texts.first_aid} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.first_aid, title: texts.first_aid,
questions: firstAidQuestions, questions: firstAidQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.flight_safety} color={colors.blue} onPress={() =>
<RowItem name={texts.flight_safety} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.flight_safety, title: texts.flight_safety,
questions: flightSafetyQuestions, questions: flightSafetyQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.instruments} color={colors.blue} onPress={() =>
<RowItem name={texts.instruments} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.instruments, title: texts.instruments,
questions: instrumentsQuestions, questions: instrumentsQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.legislation} color={colors.blue} onPress={() =>
<RowItem name={texts.legislation} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.legislation, title: texts.legislation,
questions: legislationQuestions, questions: legislationQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.materials} color={colors.blue} onPress={() =>
<RowItem name={texts.materials} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.materials, title: texts.materials,
questions: materialsQuestions, questions: materialsQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.meteorology} color={colors.blue} onPress={() =>
<RowItem name={texts.meteorology} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.meteorology, title: texts.meteorology,
questions: meteorologyQuestions, questions: meteorologyQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.physiopathology} color={colors.blue} onPress={() =>
<RowItem name={texts.physiopathology} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.physiopathology, title: texts.physiopathology,
questions: physiopathologyQuestions, questions: physiopathologyQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.piloting_techniques} color={colors.blue} onPress={() =>
<RowItem name={texts.piloting_techniques} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.piloting_techniques, title: texts.piloting_techniques,
questions: pilotingTechniquesQuestions, questions: pilotingTechniquesQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.exam} color={colors.blue} onPress={() =>
<RowItem name={texts.exam} color={colors.yellow} textColor={colors.black} onPress={() =>
navigation.navigate("Exam", { navigation.navigate("Exam", {
title: texts.exam, title: texts.exam,
questions: examQuestions, questions: examQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name="TEST" color={colors.orange} onPress={() =>
navigation.navigate("Quiz", {
title: "TEST",
questions: testQuestions,
color: colors.blue
})}/>
</ScrollView> </ScrollView>
) )

Loading…
Cancel
Save