|
@@ -17,20 +17,16 @@
|
17
|
17
|
* along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
|
18
|
18
|
*/
|
19
|
19
|
|
20
|
|
-import React, { useState } from 'react';
|
|
20
|
+import React from 'react';
|
21
|
21
|
import i18n from 'i18n-js';
|
22
|
|
-import { Snackbar } from 'react-native-paper';
|
23
|
22
|
import {
|
24
|
23
|
RefreshControl,
|
25
|
24
|
SectionListData,
|
26
|
25
|
SectionListProps,
|
27
|
26
|
StyleSheet,
|
28
|
|
- View,
|
29
|
27
|
} from 'react-native';
|
30
|
28
|
import ErrorView from './ErrorView';
|
31
|
|
-import { TAB_BAR_HEIGHT } from '../Tabbar/CustomTabBar';
|
32
|
29
|
import CollapsibleSectionList from '../Collapsible/CollapsibleSectionList';
|
33
|
|
-import GENERAL_STYLES from '../../constants/Styles';
|
34
|
30
|
import RequestScreen, { RequestScreenProps } from './RequestScreen';
|
35
|
31
|
import { CollapsibleComponentPropsType } from '../Collapsible/CollapsibleComponent';
|
36
|
32
|
import { REQUEST_CODES, REQUEST_STATUS } from '../../utils/Requests';
|
|
@@ -89,12 +85,6 @@ const styles = StyleSheet.create({
|
89
|
85
|
* To force the component to update, change the value of updateData.
|
90
|
86
|
*/
|
91
|
87
|
function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
|
92
|
|
- const [snackbarVisible, setSnackbarVisible] = useState(false);
|
93
|
|
-
|
94
|
|
- const showSnackBar = () => setSnackbarVisible(true);
|
95
|
|
-
|
96
|
|
- const hideSnackBar = () => setSnackbarVisible(false);
|
97
|
|
-
|
98
|
88
|
const getItemLayout = (
|
99
|
89
|
height: number,
|
100
|
90
|
_data: Array<SectionListData<ItemT>> | null,
|
|
@@ -124,9 +114,6 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
|
124
|
114
|
status,
|
125
|
115
|
code
|
126
|
116
|
);
|
127
|
|
- if (!data && !loading) {
|
128
|
|
- showSnackBar();
|
129
|
|
- }
|
130
|
117
|
return (
|
131
|
118
|
<CollapsibleSectionList
|
132
|
119
|
{...props}
|
|
@@ -162,7 +149,7 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
|
162
|
149
|
button={{
|
163
|
150
|
icon: 'refresh',
|
164
|
151
|
text: i18n.t('general.retry'),
|
165
|
|
- onPress: refreshData,
|
|
152
|
+ onPress: () => refreshData(),
|
166
|
153
|
}}
|
167
|
154
|
/>
|
168
|
155
|
)
|
|
@@ -175,32 +162,16 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
|
175
|
162
|
};
|
176
|
163
|
|
177
|
164
|
return (
|
178
|
|
- <View style={GENERAL_STYLES.flex}>
|
179
|
|
- <RequestScreen<RawData>
|
180
|
|
- request={props.request}
|
181
|
|
- render={render}
|
182
|
|
- showError={false}
|
183
|
|
- showLoading={false}
|
184
|
|
- autoRefreshTime={props.autoRefreshTime}
|
185
|
|
- refreshOnFocus={props.refreshOnFocus}
|
186
|
|
- cache={props.cache}
|
187
|
|
- onCacheUpdate={props.onCacheUpdate}
|
188
|
|
- />
|
189
|
|
- <Snackbar
|
190
|
|
- visible={snackbarVisible}
|
191
|
|
- onDismiss={hideSnackBar}
|
192
|
|
- action={{
|
193
|
|
- label: 'OK',
|
194
|
|
- onPress: hideSnackBar,
|
195
|
|
- }}
|
196
|
|
- duration={4000}
|
197
|
|
- style={{
|
198
|
|
- bottom: TAB_BAR_HEIGHT,
|
199
|
|
- }}
|
200
|
|
- >
|
201
|
|
- {i18n.t('general.listUpdateFail')}
|
202
|
|
- </Snackbar>
|
203
|
|
- </View>
|
|
165
|
+ <RequestScreen<RawData>
|
|
166
|
+ request={props.request}
|
|
167
|
+ render={render}
|
|
168
|
+ showError={false}
|
|
169
|
+ showLoading={false}
|
|
170
|
+ autoRefreshTime={props.autoRefreshTime}
|
|
171
|
+ refreshOnFocus={props.refreshOnFocus}
|
|
172
|
+ cache={props.cache}
|
|
173
|
+ onCacheUpdate={props.onCacheUpdate}
|
|
174
|
+ />
|
204
|
175
|
);
|
205
|
176
|
}
|
206
|
177
|
|