Browse Source

Fix crash on equipment screen enter

Arnaud Vergnet 3 years ago
parent
commit
4c29e146bb
1 changed files with 11 additions and 17 deletions
  1. 11
    17
      src/screens/Amicale/Equipment/EquipmentListScreen.js

+ 11
- 17
src/screens/Amicale/Equipment/EquipmentListScreen.js View File

39
 const LIST_ITEM_HEIGHT = 64;
39
 const LIST_ITEM_HEIGHT = 64;
40
 
40
 
41
 class EquipmentListScreen extends React.Component<PropsType, StateType> {
41
 class EquipmentListScreen extends React.Component<PropsType, StateType> {
42
-  data: Array<DeviceType>;
43
-
44
-  userRents: Array<RentedDeviceType>;
42
+  userRents: null | Array<RentedDeviceType>;
45
 
43
 
46
   authRef: {current: null | AuthenticatedScreen};
44
   authRef: {current: null | AuthenticatedScreen};
47
 
45
 
79
 
77
 
80
   getUserDeviceRentDates(item: DeviceType): [number, number] | null {
78
   getUserDeviceRentDates(item: DeviceType): [number, number] | null {
81
     let dates = null;
79
     let dates = null;
82
-    this.userRents.forEach((device: RentedDeviceType) => {
83
-      if (item.id === device.device_id) {
84
-        dates = [device.begin, device.end];
85
-      }
86
-    });
80
+    if (this.userRents != null) {
81
+      this.userRents.forEach((device: RentedDeviceType) => {
82
+        if (item.id === device.device_id) {
83
+          dates = [device.begin, device.end];
84
+        }
85
+      });
86
+    }
87
     return dates;
87
     return dates;
88
   }
88
   }
89
 
89
 
123
    * @returns {*}
123
    * @returns {*}
124
    */
124
    */
125
   getScreen = (data: Array<ApiGenericDataType | null>): React.Node => {
125
   getScreen = (data: Array<ApiGenericDataType | null>): React.Node => {
126
-    if (data[0] != null) {
127
-      const fetchedData = data[0];
128
-      if (fetchedData != null) this.data = fetchedData.devices;
129
-    }
130
-    if (data[1] != null) {
131
-      const fetchedData = data[1];
132
-      if (fetchedData != null) this.userRents = fetchedData.locations;
133
-    }
126
+    const [allDevices, userRents] = data;
127
+    if (userRents != null) this.userRents = userRents.locations;
134
     return (
128
     return (
135
       <CollapsibleFlatList
129
       <CollapsibleFlatList
136
         keyExtractor={this.keyExtractor}
130
         keyExtractor={this.keyExtractor}
137
         renderItem={this.getRenderItem}
131
         renderItem={this.getRenderItem}
138
         ListHeaderComponent={this.getListHeader()}
132
         ListHeaderComponent={this.getListHeader()}
139
-        data={this.data}
133
+        data={allDevices != null ? allDevices.devices : null}
140
       />
134
       />
141
     );
135
     );
142
   };
136
   };

Loading…
Cancel
Save