Browse Source

Remove annoying snackbar

Arnaud Vergnet 2 years ago
parent
commit
e7cffde198

+ 5
- 1
src/components/Screens/ErrorView.tsx View File

@@ -132,7 +132,11 @@ function getMessage(props: Props) {
132 132
     }
133 133
   }
134 134
 
135
-  fullMessage.message += `\n\nCode {${props.status}:${props.code}}`;
135
+  if (props.code !== undefined) {
136
+    fullMessage.message += `\n\nCode {${props.status}:${props.code}}`;
137
+  } else {
138
+    fullMessage.message += `\n\nCode {${props.status}}`;
139
+  }
136 140
   if (props.message != null) {
137 141
     fullMessage.message = props.message;
138 142
   }

+ 12
- 41
src/components/Screens/WebSectionList.tsx View File

@@ -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
 

+ 10
- 8
src/utils/customHooks.tsx View File

@@ -78,12 +78,14 @@ export function useRequestLogic<T>(
78 78
     }
79 79
     if (canRefresh) {
80 80
       if (!response.loading) {
81
-        setResponse((prevState) => ({
82
-          ...prevState,
81
+        setResponse({
82
+          ...response,
83 83
           loading: true,
84
-        }));
84
+        });
85 85
       }
86 86
       const r = newRequest ? newRequest : request;
87
+      console.log(r);
88
+
87 89
       r()
88 90
         .then((requestResponse: T) => {
89 91
           setResponse({
@@ -98,13 +100,13 @@ export function useRequestLogic<T>(
98 100
           }
99 101
         })
100 102
         .catch(() => {
101
-          setResponse((prevState) => ({
103
+          setResponse({
102 104
             loading: false,
103
-            lastRefreshDate: prevState.lastRefreshDate,
105
+            lastRefreshDate: response.lastRefreshDate,
104 106
             status: REQUEST_STATUS.CONNECTION_ERROR,
105
-            code: 0,
106
-            data: prevState.data,
107
-          }));
107
+            code: undefined,
108
+            data: response.data,
109
+          });
108 110
         });
109 111
     }
110 112
   };

Loading…
Cancel
Save