-
Notifications
You must be signed in to change notification settings - Fork 5
/
AddLeagueFromLink.js
50 lines (44 loc) · 1.42 KB
/
AddLeagueFromLink.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
import React from "react";
import { Alert, Linking } from "react-native";
import { compose, graphql } from "react-apollo";
import * as Expo from "expo";
import * as Amplitude from 'expo-analytics-amplitude';
import ADD_LEAGUE_ID from "../../graphql/AddLeagueId";
class AddLeagueFromLink extends React.Component {
componentDidMount() {
Linking.getInitialURL().then(url => this._handleUrl(url));
Linking.addEventListener("url", ({ url }) => this._handleUrl(url));
}
_handleUrl = url => {
let { path, queryParams } = Expo.Linking.parse(url);
if (path !== "add_league") return;
const { leagueId, leagueTitle } = queryParams;
if (this.props.leagueIds.indexOf(leagueId) !== -1) {
this.props.openLeague(leagueId);
} else if (leagueId && leagueTitle) {
Alert.alert(
"Add league",
`Do you want to add the league ${leagueTitle}?`,
[
{
text: "Yes",
onPress: async () => {
Amplitude.logEventWithProperties("AddLeagueFromLink", {
leagueId
});
await this.props.addLeagueIdMutation({ variables: { leagueId } });
this.props.openLeaguesList();
}
},
{ text: "Cancel", style: "cancel" }
]
);
}
};
render() {
return null;
}
}
export default compose(graphql(ADD_LEAGUE_ID, { name: "addLeagueIdMutation" }))(
AddLeagueFromLink
);