Browse Source

fix proxiwash change not auto refreshing list

Arnaud Vergnet 2 years ago
parent
commit
fe96d9f8a1

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

41
 
41
 
42
 type Props<T> = RequestScreenProps<T>;
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
 export default function RequestScreen<T>(props: Props<T>) {
46
 export default function RequestScreen<T>(props: Props<T>) {
47
   const navigation = useNavigation<StackNavigationProp<any>>();
47
   const navigation = useNavigation<StackNavigationProp<any>>();
94
           clearInterval(refreshInterval.current);
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
   const isErrorCritical = (e: API_REQUEST_CODES | undefined) => {
100
   const isErrorCritical = (e: API_REQUEST_CODES | undefined) => {

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

44
 > &
44
 > &
45
   Omit<
45
   Omit<
46
     RequestScreenProps<RawData>,
46
     RequestScreenProps<RawData>,
47
-    | 'render'
48
-    | 'showLoading'
49
-    | 'showError'
50
-    | 'refresh'
51
-    | 'onFinish'
52
-    | 'onMajorError'
47
+    'render' | 'showLoading' | 'showError' | 'onMajorError'
53
   > &
48
   > &
54
   Omit<
49
   Omit<
55
     SectionListProps<ItemT>,
50
     SectionListProps<ItemT>,
171
       refreshOnFocus={props.refreshOnFocus}
166
       refreshOnFocus={props.refreshOnFocus}
172
       cache={props.cache}
167
       cache={props.cache}
173
       onCacheUpdate={props.onCacheUpdate}
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
   ProxiwashPreferenceKeys,
59
   ProxiwashPreferenceKeys,
60
 } from '../../utils/asyncStorage';
60
 } from '../../utils/asyncStorage';
61
 import { useProxiwashPreferences } from '../../context/preferencesContext';
61
 import { useProxiwashPreferences } from '../../context/preferencesContext';
62
+import { useSubsequentEffect } from '../../utils/customHooks';
62
 
63
 
63
 const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds
64
 const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds
64
 const LIST_ITEM_HEIGHT = 64;
65
 const LIST_ITEM_HEIGHT = 64;
106
     ProxiwashPreferenceKeys.proxiwashNotifications,
107
     ProxiwashPreferenceKeys.proxiwashNotifications,
107
     preferences
108
     preferences
108
   );
109
   );
110
+  const [refresh, setRefresh] = useState(false);
109
 
111
 
110
   const getMachinesWatched = () => {
112
   const getMachinesWatched = () => {
111
     const data = getPreferenceObject(
113
     const data = getPreferenceObject(
130
   const machinesWatched: Array<ProxiwashMachineType> = getMachinesWatched();
132
   const machinesWatched: Array<ProxiwashMachineType> = getMachinesWatched();
131
   const selectedWash: 'washinsa' | 'tripodeB' = getSelectedWash();
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
   const modalStateStrings: { [key in MachineStates]: string } = {
140
   const modalStateStrings: { [key in MachineStates]: string } = {
134
     [MachineStates.AVAILABLE]: i18n.t('screens.proxiwash.modal.ready'),
141
     [MachineStates.AVAILABLE]: i18n.t('screens.proxiwash.modal.ready'),
135
     [MachineStates.RUNNING]: i18n.t('screens.proxiwash.modal.running'),
142
     [MachineStates.RUNNING]: i18n.t('screens.proxiwash.modal.running'),
446
     default:
453
     default:
447
       data = ProxiwashConstants.washinsa;
454
       data = ProxiwashConstants.washinsa;
448
   }
455
   }
456
+
449
   return (
457
   return (
450
     <View style={GENERAL_STYLES.flex}>
458
     <View style={GENERAL_STYLES.flex}>
451
       <View style={styles.container}>
459
       <View style={styles.container}>
458
           refreshOnFocus={true}
466
           refreshOnFocus={true}
459
           extraData={machinesWatched.length}
467
           extraData={machinesWatched.length}
460
           renderListHeaderComponent={renderListHeaderComponent}
468
           renderListHeaderComponent={renderListHeaderComponent}
469
+          refresh={refresh}
470
+          onFinish={() => setRefresh(false)}
461
         />
471
         />
462
       </View>
472
       </View>
463
       <MascotPopup
473
       <MascotPopup

Loading…
Cancel
Save