@ -1,7 +1,15 @@
import React from "react" ;
import { View , ScrollView , StyleSheet , Text , Image , BackHandler } from "react-native" ;
import SafeAreaView from 'react-native-safe-area-view' ;
import AsyncStorage from '@react-native-async-storage/async-storage' ;
import React , { useEffect , useState , useCallback } from "react" ;
import {
View ,
ScrollView ,
StyleSheet ,
Text ,
Image ,
BackHandler ,
} from "react-native" ;
import { SafeAreaView } from "react-native-safe-area-context" ;
import AsyncStorage from "@react-native-async-storage/async-storage" ;
import { useNavigation , useRoute , useFocusEffect } from "@react-navigation/native" ;
import { Button , ButtonContainer } from "../components/Button" ;
import { Banner } from "../components/Banner" ;
@ -26,120 +34,168 @@ const allQuestions = {
materials : materialsQuestions ,
meteorology : meteorologyQuestions ,
physiopathology : physiopathologyQuestions ,
pilotingTechniques : pilotingTechniquesQuestions
pilotingTechniques : pilotingTechniquesQuestions ,
} ;
const header = require ( "../assets/header.png" ) ;
const styles = StyleSheet . create ( {
container : { backgroundColor : colors . dark_blue , flex : 1 } ,
safearea : { flex : 1 , marginTop : 0 , justifyContent : "space-between" , paddingHorizontal : 20 , paddingBottom : 40 } ,
headerContainer : { marginTop : - 40 , alignItems : "center" , justifyContent : "center" , width : "100%" , height : 200 } ,
safearea : {
flex : 1 ,
marginTop : 0 ,
justifyContent : "space-between" ,
paddingHorizontal : 20 ,
paddingBottom : 40 ,
} ,
headerContainer : {
marginTop : - 40 ,
alignItems : "center" ,
justifyContent : "center" ,
width : "100%" ,
height : 200 ,
} ,
header : { width : "100%" } ,
box : { marginTop : 30 , borderColor : colors . black_alpha , borderWidth : 1 , padding : 15 , borderRadius : 5 , backgroundColor : colors . white_alpha } ,
text : { color : colors . white , fontSize : 20 , textAlign : "center" , fontWeight : "600" , paddingTop : 0 } ,
textCode : { color : colors . white , fontSize : 12 , textAlign : "center" , fontWeight : "500" , paddingTop : 10 , paddingBottom : 0 } ,
textBig : { color : colors . white , fontSize : 22 , textAlign : "center" , fontWeight : "400" , paddingBottom : 15 , textTransform : "uppercase" , textShadowColor : 'rgba(0, 0, 0, 0.75)' , textShadowOffset : { width : - 1 , height : 1 } , textShadowRadius : 10 } ,
bannerContainer : { flex : 1 , alignItems : "center" , justifyContent : "center" }
box : {
marginTop : 30 ,
borderColor : colors . black_alpha ,
borderWidth : 1 ,
padding : 15 ,
borderRadius : 5 ,
backgroundColor : colors . white_alpha ,
} ,
text : {
color : colors . white ,
fontSize : 20 ,
textAlign : "center" ,
fontWeight : "600" ,
paddingTop : 0 ,
} ,
textCode : {
color : colors . white ,
fontSize : 12 ,
textAlign : "center" ,
fontWeight : "500" ,
paddingTop : 10 ,
paddingBottom : 0 ,
} ,
textBig : {
color : colors . white ,
fontSize : 22 ,
textAlign : "center" ,
fontWeight : "400" ,
paddingBottom : 15 ,
textTransform : "uppercase" ,
textShadowColor : "rgba(0, 0, 0, 0.75)" ,
textShadowOffset : { width : - 1 , height : 1 } ,
textShadowRadius : 10 ,
} ,
bannerContainer : { flex : 1 , alignItems : "center" , justifyContent : "center" } ,
} ) ;
class Recap extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
storeWrongAnswers : [ ]
} ;
}
const Recap = ( ) => {
const navigation = useNavigation ( ) ;
const route = useRoute ( ) ;
const [ storeWrongAnswers , setStoreWrongAnswers ] = useState ( [ ] ) ;
componentDidMount ( ) {
this . backHandler = BackHandler . addEventListener ( 'hardwareBackPress' , this . handleBackButton ) ;
AsyncStorage . getItem ( 'storeWrongAnswers' ) . then ( value => {
// Load stored wrong answers
useEffect ( ( ) => {
AsyncStorage . getItem ( "storeWrongAnswers" ) . then ( ( value ) => {
if ( value ) {
this . setState ( { storeWrongAnswers : JSON . parse ( value ) } ) ;
setStoreWrongAnswers ( JSON . parse ( value ) ) ;
}
} ) ;
}
componentWillUnmount ( ) {
this . backHandler ? . remove ( ) ;
}
} , [ ] ) ;
handleBackButton = ( ) => {
const handleBackButton = useCallback ( ( ) => {
const tmpQuestions = [ ] ;
AsyncStorage . getItem ( 'setupData' ) . then ( value => {
AsyncStorage . getItem ( "setupData" ) . then ( ( value ) => {
const setupData = JSON . parse ( value ) || { } ;
examScheme . forEach ( elem => {
examScheme . forEach ( ( elem ) => {
let currentSection = setupData . excludeDelta
? allQuestions [ elem . section ] . filter ( item => ! item . delta )
? allQuestions [ elem . section ] . filter ( ( item ) => ! item . delta )
: allQuestions [ elem . section ] ;
for ( let i = 0 ; i < elem . questions ; i ++ ) {
const currentIndex = Math . floor ( Math . random ( ) * currentSection . length ) ;
tmpQuestions . push ( currentSection [ currentIndex ] ) ;
currentSection = currentSection . filter ( ( _ , in de x ) => in de x !== currentIndex ) ;
currentSection = currentSection . filter ( ( _ , idx ) => idx !== currentIndex ) ;
}
} ) ;
this . props . navigation . navigate ( "Splash" , {
navigation . navigate ( "Splash" , {
examQuestions : tmpQuestions ,
storeWrongAnswers : this . state . storeWrongAnswers
storeWrongAnswers ,
} ) ;
} ) ;
return true ;
}
render ( ) {
const questions = this . props . route . params ? . wrongAnswers || [ ] ;
return (
< View style = { styles . container } >
< View style = { styles . headerContainer } >
< Image source = { header } style = { styles . header } resizeMode = "contain" / >
< / V i e w >
} , [ navigation , storeWrongAnswers ] ) ;
// Attach hardware back handler
useFocusEffect (
useCallback ( ( ) => {
const backHandler = BackHandler . addEventListener (
"hardwareBackPress" ,
handleBackButton
) ;
return ( ) => backHandler . remove ( ) ;
} , [ handleBackButton ] )
) ;
const questions = route . params ? . wrongAnswers || [ ] ;
return (
< View style = { styles . container } >
< View style = { styles . headerContainer } >
< Image source = { header } style = { styles . header } resizeMode = "contain" / >
< / V i e w >
< Text style = { styles . textBig } > { texts . recapTitle } < / T e x t >
< ScrollView >
< SafeAreaView style = { styles . safearea } >
{ questions . map ( question => (
< View style = { styles . box } key = { question . id } >
< Text style = { styles . textCode } > { question . id } < / T e x t >
< Text style = { styles . text } > { question . question } < / T e x t >
< ButtonContainer >
{ question . answers . map ( answer => (
< Button
key = { answer . id }
text = { answer . text }
colorize = { { id : answer . id , clicked : question . clicked , answered : true , isCorrect : answer . correct } }
/ >
) ) }
< / B u t t o n C o n t a i n e r >
< / V i e w >
) ) }
< View style = { { marginTop : 20 } } >
< Button
color = { colors . white_alpha2 }
hasShadow
hasBg
text = { texts . restart }
onPress = { this . handleBackButton }
/ >
< Text style = { styles . textBig } > aaa { texts . recapTitle } < / T e x t >
< ScrollView >
< SafeAreaView style = { styles . safearea } >
{ questions . map ( ( question ) => (
< View style = { styles . box } key = { question . id } >
< Text style = { styles . textCode } > { question . id } < / T e x t >
< Text style = { styles . text } > { question . question } < / T e x t >
< ButtonContainer >
{ question . answers . map ( ( answer ) => (
< Button
key = { answer . id }
text = { answer . text }
colorize = { {
id : answer . id ,
clicked : question . clicked ,
answered : true ,
isCorrect : answer . correct ,
} }
/ >
) ) }
< / B u t t o n C o n t a i n e r >
< / V i e w >
< / S a f e A r e a V i e w >
< View style = { styles . bannerContainer } >
< Banner / >
) ) }
< View style = { { marginTop : 20 } } >
< Button
color = { colors . white_alpha2 }
hasShadow
hasBg
text = { texts . restart }
onPress = { handleBackButton }
/ >
< / V i e w >
< / S c r o l l V i e w >
< / V i e w >
) ;
}
}
< / S a f e A r e a V i e w >
< View style = { styles . bannerContainer } >
< Banner / >
< / V i e w >
< / S c r o l l V i e w >
< / V i e w >
) ;
} ;
export default Recap ;