diff --git a/components/AuthenticatedScreen.js b/components/AuthenticatedScreen.js index 32a8a8b..7e71cab 100644 --- a/components/AuthenticatedScreen.js +++ b/components/AuthenticatedScreen.js @@ -1,8 +1,10 @@ +// @flow + import * as React from 'react'; -import {StyleSheet, View} from "react-native"; -import {ActivityIndicator, Subheading, withTheme} from 'react-native-paper'; +import {View} from "react-native"; +import {ActivityIndicator, withTheme} from 'react-native-paper'; import ConnectionManager, {ERROR_TYPE} from "../managers/ConnectionManager"; -import {MaterialCommunityIcons} from "@expo/vector-icons"; +import NetworkErrorComponent from "./NetworkErrorComponent"; type Props = { navigation: Object, @@ -41,14 +43,14 @@ class AuthenticatedScreen extends React.Component { this.fetchData(); } - fetchData() { + fetchData = () => { if (!this.state.loading) this.setState({loading: true}); this.connectionManager.isLoggedIn() .then(() => { this.connectionManager.authenticatedRequest(this.props.link) .then((data) => { - this.onFinishedLoading(data); + this.onFinishedLoading(data, -1); }) .catch((error) => { this.onFinishedLoading(undefined, error); @@ -57,7 +59,7 @@ class AuthenticatedScreen extends React.Component { .catch((error) => { this.onFinishedLoading(undefined, ERROR_TYPE.BAD_CREDENTIALS); }); - } + }; onFinishedLoading(data: Object, error: number) { this.data = data; @@ -113,22 +115,12 @@ class AuthenticatedScreen extends React.Component { } return ( - - - - - - - {message} - - - + ); } @@ -143,22 +135,4 @@ class AuthenticatedScreen extends React.Component { } } -const styles = StyleSheet.create({ - outer: { - flex: 1, - }, - inner: { - marginTop: 'auto', - marginBottom: 'auto', - }, - iconContainer: { - marginLeft: 'auto', - marginRight: 'auto', - marginBottom: 20 - }, - subheading: { - textAlign: 'center', - } -}); - export default withTheme(AuthenticatedScreen); diff --git a/components/LogoutDialog.js b/components/LogoutDialog.js index 60f25c8..1df0433 100644 --- a/components/LogoutDialog.js +++ b/components/LogoutDialog.js @@ -1,3 +1,5 @@ +// @flow + import * as React from 'react'; import {ActivityIndicator, Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper'; import ConnectionManager from "../managers/ConnectionManager"; diff --git a/components/NetworkErrorComponent.js b/components/NetworkErrorComponent.js new file mode 100644 index 0000000..4afe444 --- /dev/null +++ b/components/NetworkErrorComponent.js @@ -0,0 +1,87 @@ +// @flow + +import * as React from 'react'; +import {Button, Subheading, withTheme} from 'react-native-paper'; +import {StyleSheet, View} from "react-native"; +import {MaterialCommunityIcons} from "@expo/vector-icons"; +import i18n from 'i18n-js'; + +type Props = { + navigation: Object, + message: string, + icon: string, + onRefresh: Function, +} + +type State = { + refreshing: boolean, +} + +class NetworkErrorComponent extends React.PureComponent { + + colors: Object; + + state = { + refreshing: false, + }; + + constructor(props) { + super(props); + this.colors = props.theme.colors; + } + + render() { + return ( + + + + + + + {this.props.message} + + + + + ); + } +} + +const styles = StyleSheet.create({ + outer: { + flex: 1, + }, + inner: { + marginTop: 'auto', + marginBottom: 'auto', + }, + iconContainer: { + marginLeft: 'auto', + marginRight: 'auto', + marginBottom: 20 + }, + subheading: { + textAlign: 'center', + }, + button: { + marginTop: 10, + marginLeft: 'auto', + marginRight: 'auto', + } +}); + + +export default withTheme(NetworkErrorComponent); diff --git a/screens/Amicale/ProfileScreen.js b/screens/Amicale/ProfileScreen.js index 5d69db4..778e106 100644 --- a/screens/Amicale/ProfileScreen.js +++ b/screens/Amicale/ProfileScreen.js @@ -1,3 +1,5 @@ +// @flow + import * as React from 'react'; import {FlatList, StyleSheet, View} from "react-native"; import {Avatar, Button, Card, Divider, List, withTheme} from 'react-native-paper'; @@ -72,7 +74,7 @@ class ProfileScreen extends React.Component { ) } - getRenderItem({item}: Object) { + getRenderItem({item}: Object): any { switch (item.id) { case '0': return this.getPersonalCard(); diff --git a/translations/en.json b/translations/en.json index 8cce92c..42d18d5 100644 --- a/translations/en.json +++ b/translations/en.json @@ -254,6 +254,7 @@ }, "general": { "loading": "Loading...", + "retry": "Retry", "networkError": "Unable to contact servers. Make sure you are connected to Internet." }, "date": { diff --git a/translations/fr.json b/translations/fr.json index 5697a5d..cc80b78 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -255,6 +255,7 @@ }, "general": { "loading": "Chargement...", + "retry": "Réessayer", "networkError": "Impossible de contacter les serveurs. Assurez-vous d'être connecté à internet." }, "date": {