|
@@ -5,7 +5,7 @@ import ThemeManager from '../utils/ThemeManager';
|
5
|
5
|
import WebDataManager from "../utils/WebDataManager";
|
6
|
6
|
import {MaterialCommunityIcons} from "@expo/vector-icons";
|
7
|
7
|
import i18n from "i18n-js";
|
8
|
|
-import {ActivityIndicator, Subheading} from 'react-native-paper';
|
|
8
|
+import {ActivityIndicator, Snackbar, Subheading} from 'react-native-paper';
|
9
|
9
|
import {RefreshControl, SectionList, View} from "react-native";
|
10
|
10
|
|
11
|
11
|
type Props = {
|
|
@@ -16,13 +16,13 @@ type Props = {
|
16
|
16
|
renderSectionHeader: React.Node,
|
17
|
17
|
stickyHeader: boolean,
|
18
|
18
|
createDataset: Function,
|
19
|
|
- updateErrorText: string,
|
20
|
19
|
}
|
21
|
20
|
|
22
|
21
|
type State = {
|
23
|
22
|
refreshing: boolean,
|
24
|
23
|
firstLoading: boolean,
|
25
|
24
|
fetchedData: Object,
|
|
25
|
+ snackbarVisible: boolean
|
26
|
26
|
};
|
27
|
27
|
|
28
|
28
|
/**
|
|
@@ -37,7 +37,7 @@ type State = {
|
37
|
37
|
export default class WebSectionList extends React.Component<Props, State> {
|
38
|
38
|
|
39
|
39
|
static defaultProps = {
|
40
|
|
- renderSectionHeader: undefined,
|
|
40
|
+ renderSectionHeader: null,
|
41
|
41
|
stickyHeader: false,
|
42
|
42
|
};
|
43
|
43
|
|
|
@@ -50,6 +50,7 @@ export default class WebSectionList extends React.Component<Props, State> {
|
50
|
50
|
refreshing: false,
|
51
|
51
|
firstLoading: true,
|
52
|
52
|
fetchedData: {},
|
|
53
|
+ snackbarVisible: false
|
53
|
54
|
};
|
54
|
55
|
|
55
|
56
|
onRefresh: Function;
|
|
@@ -57,6 +58,8 @@ export default class WebSectionList extends React.Component<Props, State> {
|
57
|
58
|
onFetchError: Function;
|
58
|
59
|
getEmptyRenderItem: Function;
|
59
|
60
|
getEmptySectionHeader: Function;
|
|
61
|
+ showSnackBar: Function;
|
|
62
|
+ hideSnackBar: Function;
|
60
|
63
|
|
61
|
64
|
constructor() {
|
62
|
65
|
super();
|
|
@@ -66,6 +69,8 @@ export default class WebSectionList extends React.Component<Props, State> {
|
66
|
69
|
this.onFetchError = this.onFetchError.bind(this);
|
67
|
70
|
this.getEmptyRenderItem = this.getEmptyRenderItem.bind(this);
|
68
|
71
|
this.getEmptySectionHeader = this.getEmptySectionHeader.bind(this);
|
|
72
|
+ this.showSnackBar = this.showSnackBar.bind(this);
|
|
73
|
+ this.hideSnackBar = this.hideSnackBar.bind(this);
|
69
|
74
|
}
|
70
|
75
|
|
71
|
76
|
/**
|
|
@@ -112,7 +117,8 @@ export default class WebSectionList extends React.Component<Props, State> {
|
112
|
117
|
refreshing: false,
|
113
|
118
|
firstLoading: false
|
114
|
119
|
});
|
115
|
|
- this.webDataManager.showUpdateToast(this.props.updateErrorText);
|
|
120
|
+ this.showSnackBar();
|
|
121
|
+ // this.webDataManager.showUpdateToast(this.props.updateErrorText);
|
116
|
122
|
}
|
117
|
123
|
|
118
|
124
|
/**
|
|
@@ -194,30 +200,51 @@ export default class WebSectionList extends React.Component<Props, State> {
|
194
|
200
|
return item.text
|
195
|
201
|
}
|
196
|
202
|
|
|
203
|
+ showSnackBar() {
|
|
204
|
+ this.setState({snackbarVisible: true})
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ hideSnackBar() {
|
|
208
|
+ this.setState({snackbarVisible: false})
|
|
209
|
+ }
|
|
210
|
+
|
197
|
211
|
render() {
|
198
|
212
|
let dataset = this.props.createDataset(this.state.fetchedData);
|
199
|
213
|
const isEmpty = dataset[0].data.length === 0;
|
200
|
|
- const shouldRenderHeader = isEmpty || (this.props.renderSectionHeader !== undefined);
|
|
214
|
+ const shouldRenderHeader = !isEmpty || (this.props.renderSectionHeader !== null);
|
201
|
215
|
if (isEmpty)
|
202
|
216
|
dataset = this.createEmptyDataset();
|
203
|
217
|
return (
|
204
|
|
- <SectionList
|
205
|
|
- sections={dataset}
|
206
|
|
- refreshControl={
|
207
|
|
- <RefreshControl
|
208
|
|
- refreshing={this.state.refreshing}
|
209
|
|
- onRefresh={this.onRefresh}
|
210
|
|
- />
|
211
|
|
- }
|
212
|
|
- renderSectionHeader={shouldRenderHeader ? this.getEmptySectionHeader : this.props.renderSectionHeader}
|
213
|
|
- renderItem={isEmpty ? this.getEmptyRenderItem : this.props.renderItem}
|
214
|
|
- style={{minHeight: 300, width: '100%'}}
|
215
|
|
- stickySectionHeadersEnabled={this.props.stickyHeader}
|
216
|
|
- contentContainerStyle={
|
217
|
|
- isEmpty ?
|
218
|
|
- {flexGrow: 1, justifyContent: 'center', alignItems: 'center'} : {}
|
219
|
|
- }
|
220
|
|
- />
|
|
218
|
+ <View>
|
|
219
|
+ <Snackbar
|
|
220
|
+ visible={this.state.snackbarVisible}
|
|
221
|
+ onDismiss={this.hideSnackBar}
|
|
222
|
+ action={{
|
|
223
|
+ label: 'OK',
|
|
224
|
+ onPress: this.hideSnackBar,
|
|
225
|
+ }}
|
|
226
|
+ duration={4000}
|
|
227
|
+ >
|
|
228
|
+ {i18n.t("homeScreen.listUpdateFail")}
|
|
229
|
+ </Snackbar>
|
|
230
|
+ <SectionList
|
|
231
|
+ sections={dataset}
|
|
232
|
+ refreshControl={
|
|
233
|
+ <RefreshControl
|
|
234
|
+ refreshing={this.state.refreshing}
|
|
235
|
+ onRefresh={this.onRefresh}
|
|
236
|
+ />
|
|
237
|
+ }
|
|
238
|
+ renderSectionHeader={shouldRenderHeader ? this.props.renderSectionHeader : this.getEmptySectionHeader}
|
|
239
|
+ renderItem={isEmpty ? this.getEmptyRenderItem : this.props.renderItem}
|
|
240
|
+ style={{minHeight: 300, width: '100%'}}
|
|
241
|
+ stickySectionHeadersEnabled={this.props.stickyHeader}
|
|
242
|
+ contentContainerStyle={
|
|
243
|
+ isEmpty ?
|
|
244
|
+ {flexGrow: 1, justifyContent: 'center', alignItems: 'center'} : {}
|
|
245
|
+ }
|
|
246
|
+ />
|
|
247
|
+ </View>
|
221
|
248
|
);
|
222
|
249
|
}
|
223
|
250
|
}
|