Browse Source

fix proxiwash change not auto refreshing list

Arnaud Vergnet 6 months ago
parent
commit
fe96d9f8a1

+ 2
- 3
src/components/Screens/RequestScreen.tsx View File

@@ -41,7 +41,7 @@ export type RequestProps = {
41 41
 
42 42
 type Props<T> = RequestScreenProps<T>;
43 43
 
44
-const MIN_REFRESH_TIME = 5 * 1000;
44
+const MIN_REFRESH_TIME = 3 * 1000;
45 45
 
46 46
 export default function RequestScreen<T>(props: Props<T>) {
47 47
   const navigation = useNavigation<StackNavigationProp<any>>();
@@ -94,8 +94,7 @@ export default function RequestScreen<T>(props: Props<T>) {
94 94
           clearInterval(refreshInterval.current);
95 95
         }
96 96
       };
97
-      // eslint-disable-next-line react-hooks/exhaustive-deps
98
-    }, [props.cache, props.refreshOnFocus])
97
+    }, [props.cache, props.refreshOnFocus, props.autoRefreshTime, refreshData])
99 98
   );
100 99
 
101 100
   const isErrorCritical = (e: API_REQUEST_CODES | undefined) => {

+ 3
- 6
src/components/Screens/WebSectionList.tsx View File

@@ -44,12 +44,7 @@ type Props<ItemT, RawData> = Omit<
44 44
 > &
45 45
   Omit<
46 46
     RequestScreenProps<RawData>,
47
-    | 'render'
48
-    | 'showLoading'
49
-    | 'showError'
50
-    | 'refresh'
51
-    | 'onFinish'
52
-    | 'onMajorError'
47
+    'render' | 'showLoading' | 'showError' | 'onMajorError'
53 48
   > &
54 49
   Omit<
55 50
     SectionListProps<ItemT>,
@@ -171,6 +166,8 @@ function WebSectionList<ItemT, RawData>(props: Props<ItemT, RawData>) {
171 166
       refreshOnFocus={props.refreshOnFocus}
172 167
       cache={props.cache}
173 168
       onCacheUpdate={props.onCacheUpdate}
169
+      refresh={props.refresh}
170
+      onFinish={props.onFinish}
174 171
     />
175 172
   );
176 173
 }

+ 10
- 0
src/screens/Proxiwash/ProxiwashScreen.tsx View File

@@ -59,6 +59,7 @@ import {
59 59
   ProxiwashPreferenceKeys,
60 60
 } from '../../utils/asyncStorage';
61 61
 import { useProxiwashPreferences } from '../../context/preferencesContext';
62
+import { useSubsequentEffect } from '../../utils/customHooks';
62 63
 
63 64
 const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds
64 65
 const LIST_ITEM_HEIGHT = 64;
@@ -106,6 +107,7 @@ function ProxiwashScreen() {
106 107
     ProxiwashPreferenceKeys.proxiwashNotifications,
107 108
     preferences
108 109
   );
110
+  const [refresh, setRefresh] = useState(false);
109 111
 
110 112
   const getMachinesWatched = () => {
111 113
     const data = getPreferenceObject(
@@ -130,6 +132,11 @@ function ProxiwashScreen() {
130 132
   const machinesWatched: Array<ProxiwashMachineType> = getMachinesWatched();
131 133
   const selectedWash: 'washinsa' | 'tripodeB' = getSelectedWash();
132 134
 
135
+  useSubsequentEffect(() => {
136
+    // Refresh the list when the selected wash changes
137
+    setRefresh(true);
138
+  }, [selectedWash]);
139
+
133 140
   const modalStateStrings: { [key in MachineStates]: string } = {
134 141
     [MachineStates.AVAILABLE]: i18n.t('screens.proxiwash.modal.ready'),
135 142
     [MachineStates.RUNNING]: i18n.t('screens.proxiwash.modal.running'),
@@ -446,6 +453,7 @@ function ProxiwashScreen() {
446 453
     default:
447 454
       data = ProxiwashConstants.washinsa;
448 455
   }
456
+
449 457
   return (
450 458
     <View style={GENERAL_STYLES.flex}>
451 459
       <View style={styles.container}>
@@ -458,6 +466,8 @@ function ProxiwashScreen() {
458 466
           refreshOnFocus={true}
459 467
           extraData={machinesWatched.length}
460 468
           renderListHeaderComponent={renderListHeaderComponent}
469
+          refresh={refresh}
470
+          onFinish={() => setRefresh(false)}
461 471
         />
462 472
       </View>
463 473
       <MascotPopup

Loading…
Cancel
Save