components/modals/ZoneModal.tsx   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 136
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 107
mnd 3
bc 3
fnc 2
dl 0
loc 136
rs 10
bpm 1.5
cpm 2.5
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B ZoneModal.tsx ➔ ZoneModal 0 68 5
1
import React from "react";
2
import { useState, useEffect } from 'react';
3
import { View, Text, TextInput, Button, Pressable, StyleSheet, Image, StatusBar, Modal } from "react-native";
4
import GestureRecognizer from 'react-native-swipe-gestures';
5
6
export default function ZoneModal({navigation, zone, zoneModalVisible, setZoneModalVisible, currentCity}) {
7
    const [zoneType, setZoneType] = useState(null);
8
    const [taxRates, setTaxRates] = useState(null);
9
    const [zoneText, setZoneText] = useState(null);
10
11
12
13
    useEffect(() => {
14
        function getZoneData() {
15
            if (zone) {
16
                setZoneType(zone['zoneType'])
17
                setTaxRates(currentCity['taxRates'])
18
19
                if (taxRates) {
20
                    if (taxRates[`${zoneType}Rate`] > 0) {
21
                        setZoneText(`Parking here will cost ${taxRates[`${zoneType}Rate`]}kr`)
22
                    } else {
23
                        setZoneText(`Park here to reduce ${taxRates[`${zoneType}Rate`]}kr from your trip`)
24
                    }
25
                }
26
                
27
            }
28
        }
29
        getZoneData();
30
    });
31
32
33
    
34
    return (
35
        <GestureRecognizer
36
            style={{flex: 1}}
37
            onSwipeDown={ () => setZoneModalVisible(false) }
38
        >
39
        <Modal
40
        animationType="slide"
41
        transparent={true}
42
        visible={zoneModalVisible}
43
        onRequestClose={() => {
44
            setZoneModalVisible(!zoneModalVisible)
45
        }}
46
47
        >
48
            <View style={styles.modalContainer}></View>
49
50
51
            <View style={styles.modalMessage}>
52
            <View style={styles.swipeButton}></View>
53
54
                <View style={styles.titleContainer}>
55
                    <View style={styles.textContainer}>
56
                    </View>
57
58
                </View>
59
                
60
                <Text style={{color: 'grey'}}> {zoneType}: {zoneText}</Text>
61
 
62
                <Pressable 
63
                style={styles.tourButton} 
64
                onPress={() => setZoneModalVisible(false)}
65
                >
66
                    <Text style={{color: 'white', fontWeight: 'bold'}}>OK</Text>
67
                </Pressable>
68
69
                
70
            </View>
71
        </Modal>
72
    </GestureRecognizer>
73
    )
74
}
75
76
const styles = StyleSheet.create({
77
    modalContainer: {
78
        width: '100%',
79
        height: '100%',
80
        flex: 1,
81
    },
82
83
    titleContainer: {
84
        flexDirection: 'row',
85
        alignItems: 'center',
86
        marginBottom: 10,
87
        marginTop: 30
88
    },
89
90
    swipeButton: {
91
        width: '25%',
92
        height: 5,
93
        backgroundColor: 'lightgrey',
94
        borderRadius: 25
95
    },
96
97
    textContainer: {
98
        width: '45%',
99
        marginBottom: 10,
100
    },
101
102
    modalMessage: {
103
        backgroundColor: 'white',
104
        width: '100%',
105
        height: '25%',
106
        justifyContent: 'flex-start',
107
        alignItems: 'center',
108
        paddingTop: 10,
109
        borderTopLeftRadius: 25,
110
        borderTopRightRadius: 25
111
    },
112
113
    scooterTitle: {
114
        fontWeight: 'bold',
115
        marginBottom: 10,
116
        fontSize: 16
117
    },
118
    
119
    battery: {
120
        marginLeft: 5,
121
    },
122
123
    scooterImage: {
124
        margin: 10
125
    },
126
127
    tourButton: {
128
        backgroundColor: 'cornflowerblue',
129
        width: '80%',
130
        height: 50,
131
        borderRadius: 25,
132
        justifyContent: 'center',
133
        alignItems: 'center',
134
        marginTop: 10
135
    },
136
})