forked from vergnet/application-amicale
Show amicale services even when not logged in
This commit is contained in:
parent
72c5a91f75
commit
fe9089881a
1 changed files with 8 additions and 69 deletions
|
@ -6,11 +6,9 @@ import CardList from "../../components/Lists/CardList/CardList";
|
||||||
import CustomTabBar from "../../components/Tabbar/CustomTabBar";
|
import CustomTabBar from "../../components/Tabbar/CustomTabBar";
|
||||||
import {withCollapsible} from "../../utils/withCollapsible";
|
import {withCollapsible} from "../../utils/withCollapsible";
|
||||||
import {Collapsible} from "react-navigation-collapsible";
|
import {Collapsible} from "react-navigation-collapsible";
|
||||||
import {CommonActions} from "@react-navigation/native";
|
|
||||||
import {Animated, View} from "react-native";
|
import {Animated, View} from "react-native";
|
||||||
import {Avatar, Button, Card, Divider, List, Title, TouchableRipple, withTheme} from "react-native-paper";
|
import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-native-paper";
|
||||||
import type {CustomTheme} from "../../managers/ThemeManager";
|
import type {CustomTheme} from "../../managers/ThemeManager";
|
||||||
import ConnectionManager from "../../managers/ConnectionManager";
|
|
||||||
import i18n from 'i18n-js';
|
import i18n from 'i18n-js';
|
||||||
import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
|
import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
|
||||||
|
|
||||||
|
@ -45,9 +43,7 @@ export type listItem = {
|
||||||
content: cardList,
|
content: cardList,
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
type State = {}
|
||||||
isLoggedIn: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
class ServicesScreen extends React.Component<Props, State> {
|
class ServicesScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
|
@ -111,12 +107,6 @@ class ServicesScreen extends React.Component<Props, State> {
|
||||||
image: TUTORINSA_IMAGE,
|
image: TUTORINSA_IMAGE,
|
||||||
onPress: () => nav.navigate("tutorinsa"),
|
onPress: () => nav.navigate("tutorinsa"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: i18n.t('screens.amicaleWebsite'),
|
|
||||||
subtitle: i18n.t('servicesScreen.descriptions.amicaleWebsite'),
|
|
||||||
image: AMICALE_IMAGE,
|
|
||||||
onPress: () => nav.navigate("amicale-website"),
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
this.insaDataset = [
|
this.insaDataset = [
|
||||||
{
|
{
|
||||||
|
@ -173,13 +163,9 @@ class ServicesScreen extends React.Component<Props, State> {
|
||||||
content: this.insaDataset
|
content: this.insaDataset
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
this.state = {
|
|
||||||
isLoggedIn: ConnectionManager.getInstance().isLoggedIn()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.navigation.addListener('focus', this.onFocus);
|
|
||||||
this.props.navigation.setOptions({
|
this.props.navigation.setOptions({
|
||||||
headerRight: this.getAboutButton,
|
headerRight: this.getAboutButton,
|
||||||
});
|
});
|
||||||
|
@ -192,21 +178,6 @@ class ServicesScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
onAboutPress = () => this.props.navigation.navigate('amicale-contact');
|
onAboutPress = () => this.props.navigation.navigate('amicale-contact');
|
||||||
|
|
||||||
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);
|
|
||||||
// reset params to prevent infinite loop
|
|
||||||
this.props.navigation.dispatch(CommonActions.setParams({nextScreen: null}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
getAvatar(props, source: string | number) {
|
getAvatar(props, source: string | number) {
|
||||||
if (typeof source === "number")
|
if (typeof source === "number")
|
||||||
return <Avatar.Image
|
return <Avatar.Image
|
||||||
|
@ -225,57 +196,25 @@ class ServicesScreen extends React.Component<Props, State> {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
getLoginMessage() {
|
|
||||||
return (
|
|
||||||
<View>
|
|
||||||
<Title style={{
|
|
||||||
marginLeft: 'auto',
|
|
||||||
marginRight: 'auto',
|
|
||||||
}}>
|
|
||||||
{i18n.t("servicesScreen.notLoggedIn")}
|
|
||||||
</Title>
|
|
||||||
<Button
|
|
||||||
icon="login"
|
|
||||||
mode="contained"
|
|
||||||
onPress={() => this.props.navigation.navigate("login")}
|
|
||||||
style={{
|
|
||||||
marginLeft: 'auto',
|
|
||||||
marginRight: 'auto',
|
|
||||||
}}>
|
|
||||||
{i18n.t("screens.login")}
|
|
||||||
</Button>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
renderItem = ({item}: { item: listItem }) => {
|
renderItem = ({item}: { item: listItem }) => {
|
||||||
const shouldShowLogin = !this.state.isLoggedIn && item.shouldLogin;
|
|
||||||
return (
|
return (
|
||||||
<TouchableRipple
|
<TouchableRipple
|
||||||
style={{
|
style={{
|
||||||
margin: 5,
|
margin: 5,
|
||||||
marginBottom: 20,
|
marginBottom: 20,
|
||||||
}}
|
}}
|
||||||
onPress={shouldShowLogin
|
onPress={() => this.props.navigation.navigate("services-section", {data: item})}
|
||||||
? undefined
|
|
||||||
: () => this.props.navigation.navigate("services-section", {data: item})}
|
|
||||||
>
|
>
|
||||||
<View>
|
<View>
|
||||||
<Card.Title
|
<Card.Title
|
||||||
title={item.title}
|
title={item.title}
|
||||||
left={(props) => this.getAvatar(props, item.image)}
|
left={(props) => this.getAvatar(props, item.image)}
|
||||||
right={shouldShowLogin
|
right={(props) => <List.Icon {...props} icon="chevron-right"/>}
|
||||||
? undefined
|
|
||||||
: (props) => <List.Icon {...props} icon="chevron-right"/>}
|
|
||||||
/>
|
/>
|
||||||
{
|
<CardList
|
||||||
shouldShowLogin
|
|
||||||
? this.getLoginMessage()
|
|
||||||
: <CardList
|
|
||||||
dataset={item.content}
|
dataset={item.content}
|
||||||
isHorizontal={true}
|
isHorizontal={true}
|
||||||
/>
|
/>
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
</TouchableRipple>
|
</TouchableRipple>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue