Improved error handling in proxiwash screen

This commit is contained in:
keplyx 2019-07-18 11:45:28 +02:00
parent 0bdcf5a4ba
commit ca1f806237
3 changed files with 60 additions and 21 deletions

View file

@ -72,6 +72,15 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
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<Props, State> {
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<Props, State> {
}
/**
* 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<Props, State> {
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<Props, State> {
*/
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'),

View file

@ -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",

View file

@ -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",