forked from vergnet/application-amicale
Fix crash on equipment screen enter
This commit is contained in:
parent
f0de0599dd
commit
4c29e146bb
1 changed files with 11 additions and 17 deletions
|
@ -39,9 +39,7 @@ export type RentedDeviceType = {
|
||||||
const LIST_ITEM_HEIGHT = 64;
|
const LIST_ITEM_HEIGHT = 64;
|
||||||
|
|
||||||
class EquipmentListScreen extends React.Component<PropsType, StateType> {
|
class EquipmentListScreen extends React.Component<PropsType, StateType> {
|
||||||
data: Array<DeviceType>;
|
userRents: null | Array<RentedDeviceType>;
|
||||||
|
|
||||||
userRents: Array<RentedDeviceType>;
|
|
||||||
|
|
||||||
authRef: {current: null | AuthenticatedScreen};
|
authRef: {current: null | AuthenticatedScreen};
|
||||||
|
|
||||||
|
@ -79,11 +77,13 @@ class EquipmentListScreen extends React.Component<PropsType, StateType> {
|
||||||
|
|
||||||
getUserDeviceRentDates(item: DeviceType): [number, number] | null {
|
getUserDeviceRentDates(item: DeviceType): [number, number] | null {
|
||||||
let dates = null;
|
let dates = null;
|
||||||
|
if (this.userRents != null) {
|
||||||
this.userRents.forEach((device: RentedDeviceType) => {
|
this.userRents.forEach((device: RentedDeviceType) => {
|
||||||
if (item.id === device.device_id) {
|
if (item.id === device.device_id) {
|
||||||
dates = [device.begin, device.end];
|
dates = [device.begin, device.end];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return dates;
|
return dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,20 +123,14 @@ class EquipmentListScreen extends React.Component<PropsType, StateType> {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
getScreen = (data: Array<ApiGenericDataType | null>): React.Node => {
|
getScreen = (data: Array<ApiGenericDataType | null>): React.Node => {
|
||||||
if (data[0] != null) {
|
const [allDevices, userRents] = data;
|
||||||
const fetchedData = data[0];
|
if (userRents != null) this.userRents = userRents.locations;
|
||||||
if (fetchedData != null) this.data = fetchedData.devices;
|
|
||||||
}
|
|
||||||
if (data[1] != null) {
|
|
||||||
const fetchedData = data[1];
|
|
||||||
if (fetchedData != null) this.userRents = fetchedData.locations;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<CollapsibleFlatList
|
<CollapsibleFlatList
|
||||||
keyExtractor={this.keyExtractor}
|
keyExtractor={this.keyExtractor}
|
||||||
renderItem={this.getRenderItem}
|
renderItem={this.getRenderItem}
|
||||||
ListHeaderComponent={this.getListHeader()}
|
ListHeaderComponent={this.getListHeader()}
|
||||||
data={this.data}
|
data={allDevices != null ? allDevices.devices : null}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue