|
@@ -2,10 +2,12 @@
|
2
|
2
|
|
3
|
3
|
import * as React from 'react';
|
4
|
4
|
import WebDataManager from "../utils/WebDataManager";
|
5
|
|
-import {Container, Tab, TabHeading, Tabs, Text} from "native-base";
|
|
5
|
+import {Container, H3, Tab, TabHeading, Tabs, Text} from "native-base";
|
6
|
6
|
import CustomHeader from "./CustomHeader";
|
7
|
7
|
import {RefreshControl, SectionList, View} from "react-native";
|
8
|
8
|
import CustomMaterialIcon from "./CustomMaterialIcon";
|
|
9
|
+import i18n from 'i18n-js';
|
|
10
|
+import ThemeManager from "../utils/ThemeManager";
|
9
|
11
|
|
10
|
12
|
type Props = {
|
11
|
13
|
navigation: Object,
|
|
@@ -69,6 +71,34 @@ export default class FetchedDataSectionList extends React.Component<Props, State
|
69
|
71
|
return <View/>;
|
70
|
72
|
}
|
71
|
73
|
|
|
74
|
+ getEmptyRenderItem(text: string, icon: string) {
|
|
75
|
+ return (
|
|
76
|
+ <View>
|
|
77
|
+ <View style={{
|
|
78
|
+ justifyContent: 'center',
|
|
79
|
+ alignItems: 'center',
|
|
80
|
+ width: '100%',
|
|
81
|
+ height: 100,
|
|
82
|
+ marginBottom: 20
|
|
83
|
+ }}>
|
|
84
|
+ <CustomMaterialIcon
|
|
85
|
+ icon={icon}
|
|
86
|
+ fontSize={100}
|
|
87
|
+ width={100}
|
|
88
|
+ color={ThemeManager.getCurrentThemeVariables().fetchedDataSectionListErrorText}/>
|
|
89
|
+ </View>
|
|
90
|
+
|
|
91
|
+ <H3 style={{
|
|
92
|
+ textAlign: 'center',
|
|
93
|
+ marginRight: 20,
|
|
94
|
+ marginLeft: 20,
|
|
95
|
+ color: ThemeManager.getCurrentThemeVariables().fetchedDataSectionListErrorText
|
|
96
|
+ }}>
|
|
97
|
+ {text}
|
|
98
|
+ </H3>
|
|
99
|
+ </View>);
|
|
100
|
+ }
|
|
101
|
+
|
72
|
102
|
/**
|
73
|
103
|
* Create the dataset to be used in the list from the data fetched
|
74
|
104
|
* @param fetchedData {Object}
|
|
@@ -78,11 +108,33 @@ export default class FetchedDataSectionList extends React.Component<Props, State
|
78
|
108
|
return [];
|
79
|
109
|
}
|
80
|
110
|
|
|
111
|
+ createEmptyDataset() {
|
|
112
|
+ return [
|
|
113
|
+ {
|
|
114
|
+ title: '',
|
|
115
|
+ data: [
|
|
116
|
+ {
|
|
117
|
+ text: this.state.refreshing ?
|
|
118
|
+ i18n.t('general.loading') :
|
|
119
|
+ i18n.t('general.networkError'),
|
|
120
|
+ icon: this.state.refreshing ?
|
|
121
|
+ 'refresh' :
|
|
122
|
+ 'access-point-network-off'
|
|
123
|
+ }
|
|
124
|
+ ],
|
|
125
|
+ keyExtractor: (item: Object) => item.text,
|
|
126
|
+ }
|
|
127
|
+ ];
|
|
128
|
+ }
|
|
129
|
+
|
81
|
130
|
hasTabs() {
|
82
|
131
|
return false;
|
83
|
132
|
}
|
84
|
133
|
|
85
|
134
|
getSectionList(dataset: Array<Object>) {
|
|
135
|
+ let isEmpty = dataset[0].data.length === 0;
|
|
136
|
+ if (isEmpty)
|
|
137
|
+ dataset = this.createEmptyDataset();
|
86
|
138
|
return (
|
87
|
139
|
<SectionList
|
88
|
140
|
sections={dataset}
|
|
@@ -93,12 +145,20 @@ export default class FetchedDataSectionList extends React.Component<Props, State
|
93
|
145
|
/>
|
94
|
146
|
}
|
95
|
147
|
renderSectionHeader={({section: {title}}) =>
|
96
|
|
- this.getRenderSectionHeader(title)
|
|
148
|
+ isEmpty ?
|
|
149
|
+ <View/> :
|
|
150
|
+ this.getRenderSectionHeader(title)
|
97
|
151
|
}
|
98
|
152
|
renderItem={({item, section}) =>
|
99
|
|
- this.getRenderItem(item, section, dataset)
|
|
153
|
+ isEmpty ?
|
|
154
|
+ this.getEmptyRenderItem(item.text, item.icon) :
|
|
155
|
+ this.getRenderItem(item, section, dataset)
|
100
|
156
|
}
|
101
|
157
|
style={{minHeight: 300, width: '100%'}}
|
|
158
|
+ contentContainerStyle={
|
|
159
|
+ isEmpty ?
|
|
160
|
+ {flexGrow: 1, justifyContent: 'center', alignItems: 'center'} : {}
|
|
161
|
+ }
|
102
|
162
|
/>
|
103
|
163
|
);
|
104
|
164
|
}
|