From 054d8f4a339aca753b7ca9ee48d7722b058aecb6 Mon Sep 17 00:00:00 2001 From: keplyx Date: Wed, 31 Jul 2019 19:11:30 +0200 Subject: [PATCH] Refresh lists on focus and every minute for proxiwash --- components/FetchedDataSectionList.js | 39 ++++++++++++++++++++++++++-- screens/HomeScreen.js | 2 +- screens/Proximo/ProximoMainScreen.js | 2 +- screens/ProxiwashScreen.js | 4 ++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/components/FetchedDataSectionList.js b/components/FetchedDataSectionList.js index b1e4fed..553571a 100644 --- a/components/FetchedDataSectionList.js +++ b/components/FetchedDataSectionList.js @@ -24,9 +24,14 @@ export default class FetchedDataSectionList extends React.Component { + this.onScreenFocus(); + } + ); + this.willBlurSubscription = this.props.navigation.addListener( + 'willBlur', + payload => { + this.onScreenBlur(); + } + ); } + onScreenFocus() { + this._onRefresh(); + if (this.refreshTime > 0) + this.refreshInterval = setInterval(() => this._onRefresh(), this.refreshTime) + } + + onScreenBlur() { + clearInterval(this.refreshInterval); + } + + + componentWillUnmount() { + this.willBlurSubscription.remove(); + this.willFocusSubscription.remove(); + + } + + _onRefresh = () => { + console.log('refresh'); this.setState({refreshing: true}); this.webDataManager.readData().then((fetchedData) => { this.setState({ diff --git a/screens/HomeScreen.js b/screens/HomeScreen.js index 51fda41..cb87939 100644 --- a/screens/HomeScreen.js +++ b/screens/HomeScreen.js @@ -27,7 +27,7 @@ function openWebLink(link) { export default class HomeScreen extends FetchedDataSectionList { constructor() { - super(DATA_URL); + super(DATA_URL, 0); } getHeaderTranslation() { diff --git a/screens/Proximo/ProximoMainScreen.js b/screens/Proximo/ProximoMainScreen.js index 5b8d17b..05cd745 100644 --- a/screens/Proximo/ProximoMainScreen.js +++ b/screens/Proximo/ProximoMainScreen.js @@ -24,7 +24,7 @@ const typesIcons = { export default class ProximoMainScreen extends FetchedDataSectionList { constructor() { - super(DATA_URL); + super(DATA_URL, 0); } getHeaderTranslation() { diff --git a/screens/ProxiwashScreen.js b/screens/ProxiwashScreen.js index 9c554b3..d6cc078 100644 --- a/screens/ProxiwashScreen.js +++ b/screens/ProxiwashScreen.js @@ -35,11 +35,13 @@ let stateColors = {}; */ export default class ProxiwashScreen extends FetchedDataSectionList { + refreshInterval : IntervalID; + /** * Creates machine state parameters using current theme and translations */ constructor() { - super(DATA_URL); + super(DATA_URL, 1000 * 60); // Refresh every minute let colors = ThemeManager.getCurrentThemeVariables(); stateColors[MACHINE_STATES.TERMINE] = colors.proxiwashFinishedColor; stateColors[MACHINE_STATES.DISPONIBLE] = colors.proxiwashReadyColor;