| Conditions | 5 |
| Total Lines | 69 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { stopLocationUpdatesAsync } from "expo-location"; |
||
| 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 | ) |
||
| 141 | }) |