forked from vergnet/application-amicale
Improved error handling in proxiwash screen
This commit is contained in:
parent
0bdcf5a4ba
commit
ca1f806237
3 changed files with 60 additions and 21 deletions
|
@ -72,6 +72,15 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
||||||
stateStrings[MACHINE_STATES.ERREUR] = i18n.t('proxiwashScreen.states.error');
|
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
|
* 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
|
data: responseJson
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} 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
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -122,12 +135,21 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
firstLoading: false
|
firstLoading: false
|
||||||
});
|
});
|
||||||
Toast.show({
|
if (this.isDataObjectValid()) {
|
||||||
text: i18n.t('proxiwashScreen.listUpdated'),
|
Toast.show({
|
||||||
buttonText: 'OK',
|
text: i18n.t('proxiwashScreen.listUpdated'),
|
||||||
type: "success",
|
buttonText: 'OK',
|
||||||
duration: 2000
|
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() {
|
render() {
|
||||||
const nav = this.props.navigation;
|
const nav = this.props.navigation;
|
||||||
const data = [
|
let data = [];
|
||||||
{
|
if (!this.isDataObjectValid()) {
|
||||||
title: i18n.t('proxiwashScreen.dryers'),
|
data = [
|
||||||
data: this.state.data.dryers === undefined ? [] : this.state.data.dryers,
|
{
|
||||||
extraData: this.state
|
title: i18n.t('proxiwashScreen.error'),
|
||||||
},
|
data: []
|
||||||
{
|
}
|
||||||
title: i18n.t('proxiwashScreen.washers'),
|
];
|
||||||
data: this.state.data.washers === undefined ? [] : this.state.data.washers,
|
} else {
|
||||||
extraData: this.state
|
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 = [
|
const loadingData = [
|
||||||
{
|
{
|
||||||
title: i18n.t('proxiwashScreen.loading'),
|
title: i18n.t('proxiwashScreen.loading'),
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
"sortName": "Sort by name",
|
"sortName": "Sort by name",
|
||||||
"sortPrice": "Sort by price",
|
"sortPrice": "Sort by price",
|
||||||
"listUpdated": "Article list updated!",
|
"listUpdated": "Article list updated!",
|
||||||
|
"listUpdateFail": "Error while updating article list",
|
||||||
"loading": "Loading...",
|
"loading": "Loading...",
|
||||||
"listTitle": "Choose a category"
|
"listTitle": "Choose a category"
|
||||||
},
|
},
|
||||||
|
@ -51,6 +52,8 @@
|
||||||
"washers": "Washers",
|
"washers": "Washers",
|
||||||
"min": "min",
|
"min": "min",
|
||||||
"listUpdated": "Machines state updated",
|
"listUpdated": "Machines state updated",
|
||||||
|
"listUpdateFail": "Error while updating machines state",
|
||||||
|
"error": "Could not update machines state. Pull down to retry.",
|
||||||
"loading": "Loading...",
|
"loading": "Loading...",
|
||||||
"states": {
|
"states": {
|
||||||
"finished": "FINISHED",
|
"finished": "FINISHED",
|
||||||
|
|
|
@ -40,7 +40,8 @@
|
||||||
"articles": "Articles",
|
"articles": "Articles",
|
||||||
"sortName": "Trier par nom",
|
"sortName": "Trier par nom",
|
||||||
"sortPrice": "Trier par prix",
|
"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...",
|
"loading": "Chargement...",
|
||||||
"listTitle": "Choisissez une catégorie"
|
"listTitle": "Choisissez une catégorie"
|
||||||
},
|
},
|
||||||
|
@ -51,6 +52,8 @@
|
||||||
"washers": "Lave Linges",
|
"washers": "Lave Linges",
|
||||||
"min": "min",
|
"min": "min",
|
||||||
"listUpdated": "Etat des machines mis à jour",
|
"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...",
|
"loading": "Chargement...",
|
||||||
"states": {
|
"states": {
|
||||||
"finished": "TERMINE",
|
"finished": "TERMINE",
|
||||||
|
|
Loading…
Reference in a new issue