Browse Source

Refresh lists on focus and every minute for proxiwash

keplyx 4 years ago
parent
commit
054d8f4a33

+ 36
- 1
components/FetchedDataSectionList.js View File

@@ -24,9 +24,14 @@ export default class FetchedDataSectionList extends React.Component<Props, State
24 24
 
25 25
     webDataManager: WebDataManager;
26 26
 
27
-    constructor(fetchUrl: string) {
27
+    willFocusSubscription : function;
28
+    willBlurSubscription : function;
29
+    refreshInterval: IntervalID;
30
+
31
+    constructor(fetchUrl: string, refreshTime : number) {
28 32
         super();
29 33
         this.webDataManager = new WebDataManager(fetchUrl);
34
+        this.refreshTime = refreshTime;
30 35
     }
31 36
 
32 37
     state = {
@@ -48,10 +53,40 @@ export default class FetchedDataSectionList extends React.Component<Props, State
48 53
      * Refresh the FetchedData on first screen load
49 54
      */
50 55
     componentDidMount() {
56
+        this.willFocusSubscription = this.props.navigation.addListener(
57
+            'willFocus',
58
+            payload => {
59
+                this.onScreenFocus();
60
+            }
61
+        );
62
+        this.willBlurSubscription = this.props.navigation.addListener(
63
+            'willBlur',
64
+            payload => {
65
+                this.onScreenBlur();
66
+            }
67
+        );
68
+    }
69
+
70
+    onScreenFocus() {
51 71
         this._onRefresh();
72
+        if (this.refreshTime > 0)
73
+            this.refreshInterval = setInterval(() => this._onRefresh(), this.refreshTime)
52 74
     }
53 75
 
76
+    onScreenBlur() {
77
+        clearInterval(this.refreshInterval);
78
+    }
79
+
80
+
81
+    componentWillUnmount() {
82
+        this.willBlurSubscription.remove();
83
+        this.willFocusSubscription.remove();
84
+
85
+    }
86
+
87
+
54 88
     _onRefresh = () => {
89
+        console.log('refresh');
55 90
         this.setState({refreshing: true});
56 91
         this.webDataManager.readData().then((fetchedData) => {
57 92
             this.setState({

+ 1
- 1
screens/HomeScreen.js View File

@@ -27,7 +27,7 @@ function openWebLink(link) {
27 27
 export default class HomeScreen extends FetchedDataSectionList {
28 28
 
29 29
     constructor() {
30
-        super(DATA_URL);
30
+        super(DATA_URL, 0);
31 31
     }
32 32
 
33 33
     getHeaderTranslation() {

+ 1
- 1
screens/Proximo/ProximoMainScreen.js View File

@@ -24,7 +24,7 @@ const typesIcons = {
24 24
 export default class ProximoMainScreen extends FetchedDataSectionList {
25 25
 
26 26
     constructor() {
27
-        super(DATA_URL);
27
+        super(DATA_URL, 0);
28 28
     }
29 29
 
30 30
     getHeaderTranslation() {

+ 3
- 1
screens/ProxiwashScreen.js View File

@@ -35,11 +35,13 @@ let stateColors = {};
35 35
  */
36 36
 export default class ProxiwashScreen extends FetchedDataSectionList {
37 37
 
38
+    refreshInterval : IntervalID;
39
+
38 40
     /**
39 41
      * Creates machine state parameters using current theme and translations
40 42
      */
41 43
     constructor() {
42
-        super(DATA_URL);
44
+        super(DATA_URL, 1000 * 60); // Refresh every minute
43 45
         let colors = ThemeManager.getCurrentThemeVariables();
44 46
         stateColors[MACHINE_STATES.TERMINE] = colors.proxiwashFinishedColor;
45 47
         stateColors[MACHINE_STATES.DISPONIBLE] = colors.proxiwashReadyColor;

Loading…
Cancel
Save