|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { ScrollView, StyleSheet, Text, View } from 'react-native'; |
| 3 | +import { SafeAreaView } from 'react-native-safe-area-context'; |
| 4 | +import BouncyCheckbox from 'react-native-bouncy-checkbox'; |
| 5 | +import { CorrectResultItem } from '../../components/CorrectResultItem'; |
| 6 | +import { IncorrectResultItem } from '../../components/IncorrectResultItem'; |
| 7 | +import { Suite } from '../../components/Suite'; |
| 8 | +import type { RouteParams } from '../../types/Results'; |
| 9 | +import { colors } from '../../styles/colors'; |
| 10 | + |
| 11 | +interface DetailsScreenProps { |
| 12 | + titlePrefix: string; |
| 13 | + route: { params: RouteParams }; |
| 14 | +} |
| 15 | + |
| 16 | +export const DetailsScreen: React.FC<DetailsScreenProps> = ({ |
| 17 | + titlePrefix, |
| 18 | + route, |
| 19 | +}) => { |
| 20 | + const { results, suiteName }: RouteParams = route.params; |
| 21 | + const [showFailed, setShowFailed] = useState<boolean>(true); |
| 22 | + const [showPassed, setShowPassed] = useState<boolean>(true); |
| 23 | + |
| 24 | + return ( |
| 25 | + <SafeAreaView style={styles.container} edges={['left', 'right']}> |
| 26 | + <View> |
| 27 | + <Text style={styles.title}> |
| 28 | + {titlePrefix} Results for '{suiteName}' Suite |
| 29 | + </Text> |
| 30 | + </View> |
| 31 | + <View style={styles.showMenu}> |
| 32 | + <View style={styles.showMenuItem}> |
| 33 | + <BouncyCheckbox |
| 34 | + isChecked={showFailed} |
| 35 | + onPress={() => setShowFailed(!showFailed)} |
| 36 | + fillColor="red" |
| 37 | + style={styles.checkbox} |
| 38 | + testID="show-failed-checkbox" |
| 39 | + disableBuiltInState={true} |
| 40 | + /> |
| 41 | + <Text style={styles.showMenuLabel}>Show Failed</Text> |
| 42 | + </View> |
| 43 | + <View style={styles.showMenuItem}> |
| 44 | + <BouncyCheckbox |
| 45 | + isChecked={showPassed} |
| 46 | + onPress={() => setShowPassed(!showPassed)} |
| 47 | + fillColor={colors.green} |
| 48 | + style={styles.checkbox} |
| 49 | + testID="show-passed-checkbox" |
| 50 | + disableBuiltInState={true} |
| 51 | + /> |
| 52 | + <Text style={styles.showMenuLabel}>Show Passed</Text> |
| 53 | + </View> |
| 54 | + </View> |
| 55 | + <ScrollView |
| 56 | + style={styles.scroll} |
| 57 | + contentContainerStyle={styles.scrollContent} |
| 58 | + > |
| 59 | + {results.map((it, index: number) => { |
| 60 | + let InnerElement = <View key={index} />; |
| 61 | + if (showPassed && it.type === 'correct') { |
| 62 | + InnerElement = ( |
| 63 | + <CorrectResultItem key={index} description={it.description} /> |
| 64 | + ); |
| 65 | + } |
| 66 | + if (showFailed && it.type === 'incorrect') { |
| 67 | + const errorMsg = it.errorMsg || ''; |
| 68 | + InnerElement = ( |
| 69 | + <IncorrectResultItem |
| 70 | + key={index} |
| 71 | + description={it.description} |
| 72 | + errorMsg={errorMsg} |
| 73 | + /> |
| 74 | + ); |
| 75 | + } |
| 76 | + if (it.type === 'grouping') { |
| 77 | + InnerElement = <Suite key={index} description={it.description} />; |
| 78 | + } |
| 79 | + return InnerElement; |
| 80 | + })} |
| 81 | + </ScrollView> |
| 82 | + </SafeAreaView> |
| 83 | + ); |
| 84 | +}; |
| 85 | + |
| 86 | +const styles = StyleSheet.create({ |
| 87 | + container: { |
| 88 | + flex: 1, |
| 89 | + paddingBottom: 30, |
| 90 | + }, |
| 91 | + title: { |
| 92 | + textAlign: 'center', |
| 93 | + paddingVertical: 5, |
| 94 | + }, |
| 95 | + showMenu: { |
| 96 | + flexDirection: 'row', |
| 97 | + width: '100%', |
| 98 | + justifyContent: 'space-evenly', |
| 99 | + paddingBottom: 5, |
| 100 | + }, |
| 101 | + showMenuItem: { |
| 102 | + flexDirection: 'row', |
| 103 | + alignItems: 'center', |
| 104 | + }, |
| 105 | + showMenuLabel: { |
| 106 | + paddingLeft: 5, |
| 107 | + }, |
| 108 | + scroll: { |
| 109 | + width: '100%', |
| 110 | + }, |
| 111 | + scrollContent: { |
| 112 | + paddingHorizontal: 5, |
| 113 | + }, |
| 114 | + checkbox: { |
| 115 | + transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }], |
| 116 | + }, |
| 117 | +}); |
0 commit comments