Compare commits
No commits in common. "2da2b631ee0d158183ef4c7c0a41fd589daeaf0f" and "0b85b1630cc06d78baa35a229696dd66cbd802cf" have entirely different histories.
2da2b631ee
...
0b85b1630c
5 changed files with 88 additions and 193 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import i18n from 'i18n-js';
|
import {ActivityIndicator, Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper';
|
||||||
import LoadingConfirmDialog from "../Custom/LoadingConfirmDialog";
|
|
||||||
import ConnectionManager from "../../managers/ConnectionManager";
|
import ConnectionManager from "../../managers/ConnectionManager";
|
||||||
|
import i18n from 'i18n-js';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: Object,
|
navigation: Object,
|
||||||
|
|
@ -11,35 +11,73 @@ type Props = {
|
||||||
onDismiss: Function,
|
onDismiss: Function,
|
||||||
}
|
}
|
||||||
|
|
||||||
class LogoutDialog extends React.PureComponent<Props> {
|
type State = {
|
||||||
|
loading: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
onClickAccept = async () => {
|
class LogoutDialog extends React.PureComponent<Props, State> {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
|
colors: Object;
|
||||||
|
|
||||||
|
state = {
|
||||||
|
loading: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.colors = props.theme.colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
onClickAccept = () => {
|
||||||
|
this.setState({loading: true});
|
||||||
ConnectionManager.getInstance().disconnect()
|
ConnectionManager.getInstance().disconnect()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.props.onDismiss();
|
||||||
|
this.setState({loading: false});
|
||||||
this.props.navigation.reset({
|
this.props.navigation.reset({
|
||||||
index: 0,
|
index: 0,
|
||||||
routes: [{name: 'Main'}],
|
routes: [{name: 'Main'}],
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
onDismiss = () => {
|
||||||
|
if (!this.state.loading)
|
||||||
this.props.onDismiss();
|
this.props.onDismiss();
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<LoadingConfirmDialog
|
<Portal>
|
||||||
{...this.props}
|
<Dialog
|
||||||
visible={this.props.visible}
|
visible={this.props.visible}
|
||||||
onDismiss={this.props.onDismiss}
|
onDismiss={this.onDismiss}>
|
||||||
onAccept={this.onClickAccept}
|
<Dialog.Title>
|
||||||
title={i18n.t("dialog.disconnect.title")}
|
{this.state.loading
|
||||||
titleLoading={i18n.t("dialog.disconnect.titleLoading")}
|
? i18n.t("dialog.disconnect.titleLoading")
|
||||||
message={i18n.t("dialog.disconnect.message")}
|
: i18n.t("dialog.disconnect.title")}
|
||||||
/>
|
</Dialog.Title>
|
||||||
|
<Dialog.Content>
|
||||||
|
{this.state.loading
|
||||||
|
? <ActivityIndicator
|
||||||
|
animating={true}
|
||||||
|
size={'large'}
|
||||||
|
color={this.colors.primary}/>
|
||||||
|
: <Paragraph>{i18n.t("dialog.disconnect.message")}</Paragraph>
|
||||||
|
}
|
||||||
|
</Dialog.Content>
|
||||||
|
{this.state.loading
|
||||||
|
? null
|
||||||
|
: <Dialog.Actions>
|
||||||
|
<Button onPress={this.onDismiss} style={{marginRight: 10}}>{i18n.t("dialog.cancel")}</Button>
|
||||||
|
<Button onPress={this.onClickAccept}>{i18n.t("dialog.yes")}</Button>
|
||||||
|
</Dialog.Actions>
|
||||||
|
}
|
||||||
|
|
||||||
|
</Dialog>
|
||||||
|
</Portal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LogoutDialog;
|
export default withTheme(LogoutDialog);
|
||||||
|
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
import * as React from 'react';
|
|
||||||
import {ActivityIndicator, Button, Dialog, Paragraph, Portal} from 'react-native-paper';
|
|
||||||
import i18n from "i18n-js";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
visible: boolean,
|
|
||||||
onDismiss: Function,
|
|
||||||
onAccept: Function, // async function to be executed
|
|
||||||
title: string,
|
|
||||||
titleLoading: string,
|
|
||||||
message: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
type State = {
|
|
||||||
loading: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoadingConfirmDialog extends React.PureComponent<Props, State> {
|
|
||||||
|
|
||||||
state = {
|
|
||||||
loading: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
onClickAccept = () => {
|
|
||||||
this.setState({loading: true});
|
|
||||||
this.props.onAccept()
|
|
||||||
.then(() => {
|
|
||||||
//Wait for fade out animations to finish before hiding loading
|
|
||||||
setTimeout(() => {
|
|
||||||
this.setState({loading: false})
|
|
||||||
}, 200);
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
onDismiss = () => {
|
|
||||||
if (!this.state.loading)
|
|
||||||
this.props.onDismiss();
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<Portal>
|
|
||||||
<Dialog
|
|
||||||
visible={this.props.visible}
|
|
||||||
onDismiss={this.onDismiss}>
|
|
||||||
<Dialog.Title>
|
|
||||||
{this.state.loading
|
|
||||||
? this.props.titleLoading
|
|
||||||
: this.props.title}
|
|
||||||
</Dialog.Title>
|
|
||||||
<Dialog.Content>
|
|
||||||
{this.state.loading
|
|
||||||
? <ActivityIndicator
|
|
||||||
animating={true}
|
|
||||||
size={'large'}/>
|
|
||||||
: <Paragraph>{this.props.message}</Paragraph>
|
|
||||||
}
|
|
||||||
</Dialog.Content>
|
|
||||||
{this.state.loading
|
|
||||||
? null
|
|
||||||
: <Dialog.Actions>
|
|
||||||
<Button onPress={this.onDismiss}
|
|
||||||
style={{marginRight: 10}}>{i18n.t("dialog.cancel")}</Button>
|
|
||||||
<Button onPress={this.onClickAccept}>{i18n.t("dialog.yes")}</Button>
|
|
||||||
</Dialog.Actions>
|
|
||||||
}
|
|
||||||
</Dialog>
|
|
||||||
</Portal>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default LoadingConfirmDialog;
|
|
||||||
|
|
@ -182,31 +182,16 @@ export default class ConnectionManager {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
generatePostArguments(keys: Array<string>, values: Array<string>) {
|
async authenticatedRequest(path: string) {
|
||||||
let data = {};
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
|
||||||
data[keys[i]] = values[i];
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async authenticatedRequest(path: string, keys: Array<string>, values: Array<any>) {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.getToken() !== null) {
|
if (this.getToken() !== null) {
|
||||||
let data = {};
|
|
||||||
if (keys !== undefined && values !== undefined && keys.length === values.length)
|
|
||||||
data = this.generatePostArguments(keys, values);
|
|
||||||
console.log(data);
|
|
||||||
fetch(API_ENDPOINT + path, {
|
fetch(API_ENDPOINT + path, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}),
|
}),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({token: this.getToken()})
|
||||||
token: this.getToken(),
|
|
||||||
...data
|
|
||||||
})
|
|
||||||
}).then(async (response) => response.json())
|
}).then(async (response) => response.json())
|
||||||
.then((response: response_format) => {
|
.then((response: response_format) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {FlatList, StyleSheet, View} from "react-native";
|
import {FlatList, ScrollView, StyleSheet} from "react-native";
|
||||||
import {Avatar, Button, Card, Divider, List, withTheme} from 'react-native-paper';
|
import {Avatar, Button, Card, Divider, List, withTheme} from 'react-native-paper';
|
||||||
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
||||||
import {openBrowser} from "../../utils/WebBrowser";
|
import {openBrowser} from "../../utils/WebBrowser";
|
||||||
|
|
@ -28,16 +28,9 @@ class ProfileScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
data: Object;
|
data: Object;
|
||||||
|
|
||||||
flatListData: Array<Object>;
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.colors = props.theme.colors;
|
this.colors = props.theme.colors;
|
||||||
this.flatListData = [
|
|
||||||
{id: '0'},
|
|
||||||
{id: '1'},
|
|
||||||
{id: '2'},
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
|
@ -58,32 +51,19 @@ class ProfileScreen extends React.Component<Props, State> {
|
||||||
getScreen = (data: Object) => {
|
getScreen = (data: Object) => {
|
||||||
this.data = data[0];
|
this.data = data[0];
|
||||||
return (
|
return (
|
||||||
<View>
|
<ScrollView>
|
||||||
{/*$FlowFixMe*/}
|
{this.getPersonalCard()}
|
||||||
<FlatList
|
{this.getClubCard()}
|
||||||
renderItem={this.getRenderItem}
|
{this.getMembershipCar()}
|
||||||
data={this.flatListData}
|
|
||||||
/>
|
|
||||||
<LogoutDialog
|
<LogoutDialog
|
||||||
{...this.props}
|
{...this.props}
|
||||||
visible={this.state.dialogVisible}
|
visible={this.state.dialogVisible}
|
||||||
onDismiss={this.hideDisconnectDialog}
|
onDismiss={this.hideDisconnectDialog}
|
||||||
/>
|
/>
|
||||||
</View>
|
</ScrollView>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
getRenderItem = ({item}: Object) => {
|
|
||||||
switch (item.id) {
|
|
||||||
case '0':
|
|
||||||
return this.getPersonalCard();
|
|
||||||
case '1':
|
|
||||||
return this.getClubCard();
|
|
||||||
case '2':
|
|
||||||
return this.getMembershipCar();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
getPersonalCard() {
|
getPersonalCard() {
|
||||||
return (
|
return (
|
||||||
<Card style={styles.card}>
|
<Card style={styles.card}>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {FlatList, StyleSheet, View} from "react-native";
|
import {FlatList, StyleSheet} from "react-native";
|
||||||
import {
|
import {
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Avatar,
|
Avatar,
|
||||||
|
|
@ -16,16 +16,19 @@ import {
|
||||||
} from 'react-native-paper';
|
} from 'react-native-paper';
|
||||||
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
||||||
import {getTimeOnlyString, stringToDate} from "../../utils/Planning";
|
import {getTimeOnlyString, stringToDate} from "../../utils/Planning";
|
||||||
import LoadingConfirmDialog from "../../components/Custom/LoadingConfirmDialog";
|
|
||||||
import ConnectionManager from "../../managers/ConnectionManager";
|
|
||||||
|
|
||||||
const ICON_AMICALE = require('../../../assets/amicale.png');
|
const ICON_AMICALE = require('../../../assets/amicale.png');
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
navigation: Object,
|
||||||
|
theme: Object,
|
||||||
|
}
|
||||||
|
|
||||||
const FAKE_DATE = {
|
const FAKE_DATE = {
|
||||||
"date_begin": "2020-04-06 21:50",
|
"date_begin": "2020-04-06 21:50",
|
||||||
"date_end": "2020-04-07 23:50",
|
"date_end": "2020-04-06 21:50",
|
||||||
"date_result_begin": "2020-04-07 21:50",
|
"date_result_begin": "2020-04-06 21:50",
|
||||||
"date_result_end": "2020-04-07 21:50",
|
"date_result_end": "2020-04-06 21:50",
|
||||||
};
|
};
|
||||||
|
|
||||||
const FAKE_DATE2 = {
|
const FAKE_DATE2 = {
|
||||||
|
|
@ -64,21 +67,14 @@ const FAKE_TEAMS2 = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {
|
|
||||||
navigation: Object,
|
|
||||||
theme: Object,
|
|
||||||
}
|
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
selectedTeam: string,
|
selectedTeam: string,
|
||||||
voteDialogVisible: boolean,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class VoteScreen extends React.Component<Props, State> {
|
class VoteScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
selectedTeam: "none",
|
selectedTeam: "none",
|
||||||
voteDialogVisible: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
colors: Object;
|
colors: Object;
|
||||||
|
|
@ -124,48 +120,18 @@ class VoteScreen extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
this.datesString = data[1];
|
this.datesString = data[1];
|
||||||
this.generateDateObject();
|
this.generateDateObject();
|
||||||
|
console.log(this.teams);
|
||||||
|
console.log(this.datesString);
|
||||||
return (
|
return (
|
||||||
<View>
|
//$FlowFixMe
|
||||||
{/*$FlowFixMe*/}
|
|
||||||
<FlatList
|
<FlatList
|
||||||
data={this.mainFlatListData}
|
data={this.mainFlatListData}
|
||||||
extraData={this.state.selectedTeam}
|
extraData={this.state.selectedTeam}
|
||||||
renderItem={this.mainRenderItem}
|
renderItem={this.mainRenderItem}
|
||||||
/>
|
/>
|
||||||
<LoadingConfirmDialog
|
|
||||||
{...this.props}
|
|
||||||
visible={this.state.voteDialogVisible}
|
|
||||||
onDismiss={this.onVoteDialogDismiss}
|
|
||||||
onAccept={this.onVoteDialogAccept}
|
|
||||||
title={"VOTE?"}
|
|
||||||
titleLoading={"SENDING VOTE..."}
|
|
||||||
message={"SURE?"}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
onVoteDialogDismiss = () => this.setState({voteDialogVisible: false});
|
|
||||||
|
|
||||||
showVoteDialog = () => this.setState({voteDialogVisible: true});
|
|
||||||
|
|
||||||
onVoteDialogAccept = async () => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
ConnectionManager.getInstance().authenticatedRequest(
|
|
||||||
"elections/vote",
|
|
||||||
["vote"],
|
|
||||||
[parseInt(this.state.selectedTeam)])
|
|
||||||
.then(() => {
|
|
||||||
this.onVoteDialogDismiss();
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.onVoteDialogDismiss();
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
generateDateObject() {
|
generateDateObject() {
|
||||||
this.dates = {
|
this.dates = {
|
||||||
date_begin: stringToDate(this.datesString.date_begin),
|
date_begin: stringToDate(this.datesString.date_begin),
|
||||||
|
|
@ -242,7 +208,7 @@ class VoteScreen extends React.Component<Props, State> {
|
||||||
};
|
};
|
||||||
|
|
||||||
onVotePress = () => {
|
onVotePress = () => {
|
||||||
this.showVoteDialog();
|
console.log("vote sent");
|
||||||
};
|
};
|
||||||
|
|
||||||
voteKeyExtractor = (item: Object) => item.id.toString();
|
voteKeyExtractor = (item: Object) => item.id.toString();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue