From fc7754588fe55887a1f1c169e326176f7c905342 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Wed, 22 Apr 2020 11:49:22 +0200 Subject: [PATCH] Improved login flow --- src/screens/Services/ServicesScreen.js | 73 ++++++++++++++++--- src/screens/Services/ServicesSectionScreen.js | 49 ++++++++----- 2 files changed, 93 insertions(+), 29 deletions(-) diff --git a/src/screens/Services/ServicesScreen.js b/src/screens/Services/ServicesScreen.js index 937cf2e..8375925 100644 --- a/src/screens/Services/ServicesScreen.js +++ b/src/screens/Services/ServicesScreen.js @@ -8,8 +8,9 @@ import {withCollapsible} from "../../utils/withCollapsible"; import {Collapsible} from "react-navigation-collapsible"; import {CommonActions} from "@react-navigation/native"; import {Animated, View} from "react-native"; -import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-native-paper"; +import {Avatar, Button, Card, Divider, List, Title, TouchableRipple, withTheme} from "react-native-paper"; import type {CustomTheme} from "../../managers/ThemeManager"; +import ConnectionManager from "../../managers/ConnectionManager"; type Props = { navigation: Object, @@ -29,14 +30,19 @@ const AMICALE_IMAGE = require("../../../assets/amicale.png"); const EE_IMAGE = "https://etud.insa-toulouse.fr/~eeinsat/wp-content/uploads/2019/09/logo-blanc.png"; const TUTORINSA_IMAGE = "https://www.etud.insa-toulouse.fr/~tutorinsa/public/images/logo-gray.png"; -type listItem = { +export type listItem = { title: string, description: string, image: string | number, + shouldLogin: boolean, content: cardList, } -class ServicesScreen extends React.Component { +type State = { + isLoggedIn: boolean, +} + +class ServicesScreen extends React.Component { amicaleDataset: cardList; studentsDataset: cardList; @@ -148,29 +154,40 @@ class ServicesScreen extends React.Component { title: "AMICALE", description: "LOGIN", image: AMICALE_IMAGE, + shouldLogin: true, content: this.amicaleDataset }, { title: "STUDENTS", description: "SERVICES OFFERED BY STUDENTS", image: 'account-group', + shouldLogin: false, content: this.studentsDataset }, { title: "INSA", description: "SERVICES OFFERED BY INSA", image: 'school', + shouldLogin: false, content: this.insaDataset }, - ] + ]; + this.state = { + isLoggedIn: ConnectionManager.getInstance().isLoggedIn() + } } componentDidMount() { - this.props.navigation.addListener('focus', this.handleNavigationParams); + this.props.navigation.addListener('focus', this.onFocus); } - handleNavigationParams = () => { + onFocus = () => { + this.handleNavigationParams(); + this.setState({isLoggedIn: ConnectionManager.getInstance().isLoggedIn()}) + } + + handleNavigationParams() { if (this.props.route.params != null) { if (this.props.route.params.nextScreen != null) { this.props.navigation.navigate(this.props.route.params.nextScreen); @@ -198,25 +215,57 @@ class ServicesScreen extends React.Component { /> } + getLoginMessage() { + return ( + + + NOT LOGGED IN + + + + ) + } + renderItem = ({item}: { item: listItem }) => { + const shouldShowLogin = !this.state.isLoggedIn && item.shouldLogin; return ( this.props.navigation.navigate("services-section", {data: item})} + onPress={shouldShowLogin + ? undefined + : () => this.props.navigation.navigate("services-section", {data: item})} > this.getAvatar(props, item.image)} - right={(props) => } - /> - } /> + { + shouldShowLogin + ? this.getLoginMessage() + : + } diff --git a/src/screens/Services/ServicesSectionScreen.js b/src/screens/Services/ServicesSectionScreen.js index a88dd2f..78bad25 100644 --- a/src/screens/Services/ServicesSectionScreen.js +++ b/src/screens/Services/ServicesSectionScreen.js @@ -1,12 +1,15 @@ // @flow import * as React from 'react'; -import type {cardList} from "../../components/Lists/CardList/CardList"; import CardList from "../../components/Lists/CardList/CardList"; import CustomTabBar from "../../components/Tabbar/CustomTabBar"; import {withCollapsible} from "../../utils/withCollapsible"; import {Collapsible} from "react-navigation-collapsible"; import {CommonActions} from "@react-navigation/native"; +import ConnectionManager from "../../managers/ConnectionManager"; +import type {listItem} from "./ServicesScreen"; +import ErrorView from "../../components/Screens/ErrorView"; +import {ERROR_TYPE} from "../../utils/WebData"; type Props = { navigation: Object, @@ -14,20 +17,29 @@ type Props = { collapsibleStack: Collapsible, } -type listItem = { - title: string, - description: string, - image: string | number, - content: cardList, +type State = { + isLoggedIn: boolean, } -class ServicesSectionScreen extends React.Component { +class ServicesSectionScreen extends React.Component { finalDataset: listItem; constructor(props) { super(props); this.handleNavigationParams(); + this.state = { + isLoggedIn: ConnectionManager.getInstance().isLoggedIn(), + } + } + + componentDidMount() { + this.props.navigation.addListener('focus', this.onFocus); + + } + + onFocus = () => { + this.setState({isLoggedIn: ConnectionManager.getInstance().isLoggedIn()}) } handleNavigationParams() { @@ -45,16 +57,19 @@ class ServicesSectionScreen extends React.Component { render() { const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack; - return + if (!this.state.isLoggedIn && this.finalDataset.shouldLogin) + return ; + else + return } }