Passed
Pull Request — dev (#13)
by Oscar
02:55
created

components/modals/ZoneModal.tsx   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 141
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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