diff --git a/screens/ProxiwashScreen.js b/screens/ProxiwashScreen.js index c9e1f40..e5d5b9d 100644 --- a/screens/ProxiwashScreen.js +++ b/screens/ProxiwashScreen.js @@ -72,6 +72,15 @@ export default class ProxiwashScreen extends React.Component { stateStrings[MACHINE_STATES.ERREUR] = i18n.t('proxiwashScreen.states.error'); } + /** + * Check if the data object contains valid entries + * + * @returns {boolean} + */ + isDataObjectValid() { + return Object.keys(this.state.data).length > 0; + } + /** * Read the data from the proxiwash scrapper and set it to current state to reload the screen * @@ -85,7 +94,11 @@ export default class ProxiwashScreen extends React.Component { data: responseJson }); } catch (error) { - console.error(error); + console.log('Could not read data from server'); + console.log(error); + this.setState({ + data: {} + }); } } @@ -111,7 +124,7 @@ export default class ProxiwashScreen extends React.Component { } /** - * Show the refresh inddicator and wait for data to be fetched from the scrapper + * Show the refresh indicator and wait for data to be fetched from the scrapper * * @private */ @@ -122,12 +135,21 @@ export default class ProxiwashScreen extends React.Component { refreshing: false, firstLoading: false }); - Toast.show({ - text: i18n.t('proxiwashScreen.listUpdated'), - buttonText: 'OK', - type: "success", - duration: 2000 - }) + if (this.isDataObjectValid()) { + Toast.show({ + text: i18n.t('proxiwashScreen.listUpdated'), + buttonText: 'OK', + type: "success", + duration: 2000 + }) + } else { + Toast.show({ + text: i18n.t('proxiwashScreen.listUpdateFail'), + buttonText: 'OK', + type: "danger", + duration: 4000 + }) + } }); }; @@ -297,18 +319,29 @@ export default class ProxiwashScreen extends React.Component { */ render() { const nav = this.props.navigation; - const data = [ - { - title: i18n.t('proxiwashScreen.dryers'), - data: this.state.data.dryers === undefined ? [] : this.state.data.dryers, - extraData: this.state - }, - { - title: i18n.t('proxiwashScreen.washers'), - data: this.state.data.washers === undefined ? [] : this.state.data.washers, - extraData: this.state - }, - ]; + let data = []; + if (!this.isDataObjectValid()) { + data = [ + { + title: i18n.t('proxiwashScreen.error'), + data: [] + } + ]; + } else { + data = [ + { + title: i18n.t('proxiwashScreen.dryers'), + data: this.state.data.dryers === undefined ? [] : this.state.data.dryers, + extraData: this.state + }, + { + title: i18n.t('proxiwashScreen.washers'), + data: this.state.data.washers === undefined ? [] : this.state.data.washers, + extraData: this.state + }, + ]; + } + const loadingData = [ { title: i18n.t('proxiwashScreen.loading'), diff --git a/translations/en.json b/translations/en.json index 47ff18b..2fcc00a 100644 --- a/translations/en.json +++ b/translations/en.json @@ -41,6 +41,7 @@ "sortName": "Sort by name", "sortPrice": "Sort by price", "listUpdated": "Article list updated!", + "listUpdateFail": "Error while updating article list", "loading": "Loading...", "listTitle": "Choose a category" }, @@ -51,6 +52,8 @@ "washers": "Washers", "min": "min", "listUpdated": "Machines state updated", + "listUpdateFail": "Error while updating machines state", + "error": "Could not update machines state. Pull down to retry.", "loading": "Loading...", "states": { "finished": "FINISHED", diff --git a/translations/fr.json b/translations/fr.json index 8b9eb61..6d787ae 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -40,7 +40,8 @@ "articles": "Articles", "sortName": "Trier par nom", "sortPrice": "Trier par prix", - "listUpdated": "Liste des articles mise à jour !", + "listUpdated": "Liste d'articles mise à jour !", + "listUpdateFail": "Erreur lors de la mise à jour de la list d'articles", "loading": "Chargement...", "listTitle": "Choisissez une catégorie" }, @@ -51,6 +52,8 @@ "washers": "Lave Linges", "min": "min", "listUpdated": "Etat des machines mis à jour", + "listUpdateFail": "Erreur lors de la mise à jour del'état des machines", + "error": "Impossible de mettre a jour l'état des machines. Tirez vers le bas pour reessayer.", "loading": "Chargement...", "states": { "finished": "TERMINE",