Compare commits

..

2 commits

Author SHA1 Message Date
3fe6be4238 Allow going back to last screen after login 2020-04-09 00:43:43 +02:00
205162605f Improved doc 2020-04-09 00:04:44 +02:00
8 changed files with 160 additions and 77 deletions

2
App.js
View file

@ -73,7 +73,7 @@ export default class App extends React.Component<Props, State> {
// Navigate to nested navigator and pass data to the index screen
this.navigatorRef.current.navigate('home', {
screen: 'index',
params: {nextScreen: route, data: data, shouldOpen: true}
params: {nextScreen: route, data: data}
});
};

View file

@ -9,6 +9,7 @@ import {ERROR_TYPE} from "../../managers/ConnectionManager";
type Props = {
navigation: Object,
route: Object,
errorCode: number,
onRefresh: Function,
}
@ -85,7 +86,11 @@ class ErrorView extends React.PureComponent<Props, State> {
</Button>;
}
goToLogin = () => this.props.navigation.navigate("login");
goToLogin = () => this.props.navigation.navigate("login",
{
screen: 'index',
params: {nextScreen: this.props.route.name}
});
getLoginButton() {
return <Button

View file

@ -19,7 +19,7 @@ type Props = {
stickyHeader: boolean,
createDataset: Function,
updateData: number,
itemHeight: number,
itemHeight: number | null,
}
type State = {
@ -43,7 +43,7 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
renderSectionHeader: null,
stickyHeader: false,
updateData: 0,
itemHeight: undefined,
itemHeight: null,
};
refreshInterval: IntervalID;
@ -198,7 +198,7 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
errorCode={ERROR_TYPE.CONNECTION_ERROR}
onRefresh={this.onRefresh}/>
}
getItemLayout={this.props.itemHeight !== undefined ? this.itemLayout : undefined}
getItemLayout={this.props.itemHeight !== null ? this.itemLayout : undefined}
/>
<Snackbar
visible={this.state.snackbarVisible}

View file

@ -169,7 +169,7 @@ function HomeStackComponent(initialRoute: string | null, defaultData: Object) {
initialParams={data}
/>
<HomeStack.Screen
name="planning-information"
name="home-planning-information"
component={PlanningDisplayScreen}
options={{
title: i18n.t('screens.planningDisplayScreen'),
@ -177,7 +177,7 @@ function HomeStackComponent(initialRoute: string | null, defaultData: Object) {
}}
/>
<HomeStack.Screen
name="club-information"
name="home-club-information"
component={ClubDisplayScreen}
options={({navigation}) => {
return {

View file

@ -7,9 +7,11 @@ import ConnectionManager from "../../managers/ConnectionManager";
import {openBrowser} from "../../utils/WebBrowser";
import i18n from 'i18n-js';
import ErrorDialog from "../../components/Dialog/ErrorDialog";
import {CommonActions} from "@react-navigation/native";
type Props = {
navigation: Object,
route: Object,
}
type State = {
@ -44,17 +46,28 @@ class LoginScreen extends React.Component<Props, State> {
onEmailChange: Function;
onPasswordChange: Function;
passwordInputRef: Object;
nextScreen: string;
constructor(props) {
super(props);
this.onEmailChange = this.onInputChange.bind(this, true);
this.onPasswordChange = this.onInputChange.bind(this, false);
this.colors = props.theme.colors;
this.props.navigation.addListener('focus', this.onScreenFocus);
}
onScreenFocus = () => {
if (this.props.route.params !== undefined && this.props.route.params.nextScreen !== undefined) {
this.nextScreen = this.props.route.params.nextScreen;
this.props.navigation.dispatch(CommonActions.setParams({nextScreen: 'profile'}));
} else
this.nextScreen = 'profile';
};
showErrorDialog = (error: number) =>
this.setState({
dialogVisible: true,
@ -63,23 +76,33 @@ class LoginScreen extends React.Component<Props, State> {
hideErrorDialog = () => this.setState({dialogVisible: false});
handleSuccess = () => this.props.navigation.navigate('profile');
handleSuccess = () => this.props.navigation.navigate(this.nextScreen);
onResetPasswordClick = () => openBrowser(RESET_PASSWORD_LINK, this.colors.primary);
validateEmail = () => this.setState({isEmailValidated: true});
isEmailValid() {return emailRegex.test(this.state.email);}
isEmailValid() {
return emailRegex.test(this.state.email);
}
shouldShowEmailError() {return this.state.isEmailValidated && !this.isEmailValid();}
shouldShowEmailError() {
return this.state.isEmailValidated && !this.isEmailValid();
}
validatePassword = () => this.setState({isPasswordValidated: true});
isPasswordValid() {return this.state.password !== '';}
isPasswordValid() {
return this.state.password !== '';
}
shouldShowPasswordError() {return this.state.isPasswordValidated && !this.isPasswordValid();}
shouldShowPasswordError() {
return this.state.isPasswordValidated && !this.isPasswordValid();
}
shouldEnableLogin() {return this.isEmailValid() && this.isPasswordValid() && !this.state.loading;}
shouldEnableLogin() {
return this.isEmailValid() && this.isPasswordValid() && !this.state.loading;
}
onInputChange(isEmail: boolean, value: string) {
if (isEmail) {

View file

@ -41,9 +41,8 @@ class ProfileScreen extends React.Component<Props, State> {
}
componentDidMount() {
const rightButton = this.getHeaderButtons.bind(this);
this.props.navigation.setOptions({
headerRight: rightButton,
headerRight: this.getHeaderButton,
});
}
@ -51,9 +50,7 @@ class ProfileScreen extends React.Component<Props, State> {
hideDisconnectDialog = () => this.setState({dialogVisible: false});
getHeaderButtons() {
return <HeaderButton icon={'logout'} onPress={this.showDisconnectDialog}/>;
}
getHeaderButton = () => <HeaderButton icon={'logout'} onPress={this.showDisconnectDialog}/>;
getScreen = (data: Object) => {
this.data = data[0];
@ -84,6 +81,67 @@ class ProfileScreen extends React.Component<Props, State> {
}
};
/**
* Checks if the given field is available
*
* @param field The field to check
* @return {boolean}
*/
isFieldAvailable(field: ?string) {
return field !== null;
}
/**
* Gets the given field value.
* If the field does not have a value, returns a placeholder text
*
* @param field The field to get the value from
* @return {*}
*/
getFieldValue(field: ?string) {
return this.isFieldAvailable(field)
? field
: i18n.t("profileScreen.noData");
}
/**
* Gets the color depending on the value.
*
* @param field The field to get the color for
* @return {*}
*/
getFieldColor(field: ?string) {
return this.isFieldAvailable(field)
? this.colors.text
: this.colors.textDisabled;
}
/**
* Gets a list item showing personal information
*
* @param field The field to display
* @param icon The icon to use
* @return {*}
*/
getPersonalListItem(field: ?string, icon: string) {
return (
<List.Item
title={this.getFieldValue(field)}
left={props => <List.Icon
{...props}
icon={icon}
color={this.getFieldColor(field)}
/>}
titleStyle={{color: this.getFieldColor(field)}}
/>
);
}
/**
* Gets a card containing user personal information
*
* @return {*}
*/
getPersonalCard() {
return (
<Card style={styles.card}>
@ -121,6 +179,11 @@ class ProfileScreen extends React.Component<Props, State> {
);
}
/**
* Gets a cars containing clubs the user is part of
*
* @return {*}
*/
getClubCard() {
return (
<Card style={styles.card}>
@ -142,6 +205,11 @@ class ProfileScreen extends React.Component<Props, State> {
);
}
/**
* Gets a card showing if the user has payed his membership
*
* @return {*}
*/
getMembershipCar() {
return (
<Card style={styles.card}>
@ -164,10 +232,38 @@ class ProfileScreen extends React.Component<Props, State> {
);
}
/**
* Gets the item showing if the user has payed his membership
*
* @return {*}
*/
getMembershipItem(state: boolean) {
return (
<List.Item
title={state ? i18n.t("profileScreen.membershipPayed") : i18n.t("profileScreen.membershipNotPayed")}
left={props => <List.Icon
{...props}
color={state ? this.colors.success : this.colors.danger}
icon={state ? 'check' : 'close'}
/>}
/>
);
}
/**
* Opens the club details screen for the club of given ID
* @param id The club's id to open
*/
openClubDetailsScreen(id: number) {
this.props.navigation.navigate("club-information", {clubId: id});
}
/**
* Gets a list item for the club list
*
* @param item The club to render
* @return {*}
*/
clubListItem = ({item}: Object) => {
const onPress = () => this.openClubDetailsScreen(0); // TODO get club id
const isManager = false; // TODO detect if manager
@ -187,6 +283,12 @@ class ProfileScreen extends React.Component<Props, State> {
clubKeyExtractor = (item: Object) => item.name;
/**
* Renders the list of clubs the user is part of
*
* @param list The club list
* @return {*}
*/
getClubList(list: Array<string>) {
let dataset = [];
for (let i = 0; i < list.length; i++) {
@ -202,49 +304,6 @@ class ProfileScreen extends React.Component<Props, State> {
);
}
getMembershipItem(state: boolean) {
return (
<List.Item
title={state ? i18n.t("profileScreen.membershipPayed") : i18n.t("profileScreen.membershipNotPayed")}
left={props => <List.Icon
{...props}
color={state ? this.colors.success : this.colors.danger}
icon={state ? 'check' : 'close'}
/>}
/>
);
}
isFieldAvailable(field: ?string) {
return field !== null;
}
getFieldValue(field: ?string) {
return this.isFieldAvailable(field)
? field
: i18n.t("profileScreen.noData");
}
getFieldColor(field: ?string) {
return this.isFieldAvailable(field)
? this.colors.text
: this.colors.textDisabled;
}
getPersonalListItem(field: ?string, icon: string) {
return (
<List.Item
title={this.getFieldValue(field)}
left={props => <List.Icon
{...props}
icon={icon}
color={this.getFieldColor(field)}
/>}
titleStyle={{color: this.getFieldColor(field)}}
/>
);
}
render() {
return (
<AuthenticatedScreen

View file

@ -39,17 +39,12 @@ type Props = {
*/
class HomeScreen extends React.Component<Props> {
getRenderItem: Function;
createDataset: Function;
colors: Object;
isLoggedIn: boolean | null;
constructor(props) {
super(props);
this.getRenderItem = this.getRenderItem.bind(this);
this.createDataset = this.createDataset.bind(this);
this.colors = props.theme.colors;
this.isLoggedIn = null;
@ -85,10 +80,10 @@ class HomeScreen extends React.Component<Props> {
handleNavigationParams = () => {
if (this.props.route.params !== undefined) {
if (this.props.route.params.shouldOpen !== undefined && this.props.route.params.shouldOpen) {
if (this.props.route.params.nextScreen !== undefined && this.props.route.params.nextScreen !== null) {
this.props.navigation.navigate(this.props.route.params.nextScreen, this.props.route.params.data);
// reset params to prevent infinite loop
this.props.navigation.dispatch(CommonActions.setParams({ shouldOpen: false }));
this.props.navigation.dispatch(CommonActions.setParams({ nextScreen: null }));
}
}
};
@ -122,7 +117,7 @@ class HomeScreen extends React.Component<Props> {
* @param fetchedData
* @return {*}
*/
createDataset(fetchedData: Object) {
createDataset = (fetchedData: Object) => {
// fetchedData = DATA;
let newsData = [];
let dashboardData = [];
@ -201,7 +196,7 @@ class HomeScreen extends React.Component<Props> {
return this.getDashboardEventItem(content);
else if (item['id'] === 'top')
return this.getDashboardTopItem(content);
else if (item['id'] === 'actions')
else
return this.getActionsDashboardItem();
}
@ -462,10 +457,11 @@ class HomeScreen extends React.Component<Props> {
* @param section The current section
* @return {*}
*/
getRenderItem({item, section}: Object) {
return (section['id'] === SECTIONS_ID[0] ?
this.getDashboardItem(item) : this.getFeedItem(item));
}
getRenderItem = ({item, section}: Object) => {
return (section['id'] === SECTIONS_ID[0]
? this.getDashboardItem(item)
: this.getFeedItem(item));
};
openScanner = () => this.props.navigation.navigate("scanner");

View file

@ -7,8 +7,8 @@ export default class URLHandler {
static CLUB_INFO_URL_PATH = "club";
static EVENT_INFO_URL_PATH = "event";
static CLUB_INFO_ROUTE = "club-information";
static EVENT_INFO_ROUTE = "planning-information";
static CLUB_INFO_ROUTE = "home-club-information";
static EVENT_INFO_ROUTE = "home-planning-information";
onInitialURLParsed: Function;
onDetectURL: Function;