-
Notifications
You must be signed in to change notification settings - Fork 5
/
LeagueScreen.js
97 lines (87 loc) · 2.69 KB
/
LeagueScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React from "react";
import { StyleSheet, ActivityIndicator } from "react-native";
import * as Amplitude from 'expo-analytics-amplitude';
import { Query } from "react-apollo";
import League from "../base/League";
import LEAGUE from "../../graphql/League";
import * as Colors from "../../constants/Colors";
import computeStandings from "../../helpers/computeStandings";
import LeagueOptions from "../base/LeagueOptions";
class LeagueScreen extends React.Component {
state = {
selectedTab: "Table"
};
constructor(props) {
super(props);
this.props.navigation.setParams({ shareLeague: this._shareLeague });
}
static navigationOptions = ({ navigation }) => {
const { leagueId, leagueTitle } = navigation.state.params;
return {
title: navigation.state.params.leagueTitle,
headerStyle: styles.header,
headerRight: (
<LeagueOptions leagueId={leagueId} leagueTitle={leagueTitle} />
)
};
};
_openCreateGame(league) {
Amplitude.logEventWithProperties("OpenCreateGame", {
leagueId: league.id
});
this.props.navigation.navigate("CreateGame", {
players: league.players,
leagueId: league.id
});
setTimeout(() => this.setState({ selectedTab: "Games" }), 200);
}
_openAddPlayer(league) {
Amplitude.logEventWithProperties("OpenCreatePlayer", {
leagueId: league.id
});
this.props.navigation.navigate("AddPlayer", {
players: league.players,
leagueId: league.id
});
setTimeout(() => this.setState({ selectedTab: "Table" }), 200);
}
render() {
const leagueId = this.props.navigation.state.params.leagueId;
return (
<Query
query={LEAGUE}
variables={{ leagueId }}
fetchPolicy="cache-and-network"
>
{({ loading, error, data, refetch, networkStatus }) => {
if (loading && !data.League)
return <ActivityIndicator style={styles.activityIndicator} />;
const league = computeStandings(data.league);
return (
<League
league={league}
refetch={refetch}
refreshing={loading}
selectedTab={this.state.selectedTab}
selectTab={selectedTab => this.setState({ selectedTab })}
openAddPlayer={() => this._openAddPlayer(data.league)}
openCreateGame={() => this._openCreateGame(data.league)}
openPlayer={player => this._openPlayer(player)}
/>
);
}}
</Query>
);
}
}
export default LeagueScreen;
const styles = StyleSheet.create({
header: {
borderBottomWidth: 0,
elevation: 0,
backgroundColor: Colors.Primary
},
activityIndicator: {
top: 40
}
});