-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.tsx
94 lines (84 loc) · 2.62 KB
/
app.tsx
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
import airbridge from 'airbridge-web-sdk-loader'
import { useEffect, useState } from 'react'
import { extract, optional } from 'tyfell'
import { AIRBRIDGE_TOKEN } from '../constants/airbridge_token'
import { AppContext } from '../entities/app_context'
import '../styles/app.css'
function App() {
const [context, setContext] = useState<AppContext | undefined>()
useEffect(() => {
// To use your app and webToken, comment this part
// ---
const url = new URL(window.location.href)
const app = (
optional.actual(url.searchParams.get('app'), 'exabr')
)
if (app === undefined) {
setContext(undefined)
return
}
setContext({
app,
webToken: AIRBRIDGE_TOKEN[app],
})
// ---
// To use your app and webToken, uncomment this part
// ---
// setContext({
// app: 'YOUR_APP',
// webToken: 'YOUR_WEB_TOKEN',
// })
// ---
}, [])
useEffect(() => {
if (context === undefined) {
return
}
airbridge.init({
app: context.app,
webToken: context.webToken,
})
}, [context])
const trackEvent = (category: string) => {
airbridge.events.send(category)
}
const openDeeplink = (url: URL) => {
airbridge.openDeeplink({
type: 'click',
deeplinks: {
ios: url.href,
android: url.href,
desktop: 'https://airbridge.io',
},
fallbacks: {
ios: 'itunes-appstore',
android: 'google-play',
},
})
}
return context !== undefined ? (
<div className="App">
<header className="App-header">
<p>Airbridge Web Example ({context.app})</p>
<button onClick={() => {
trackEvent('example-event')
}}>Track Event</button>
{ extract(window, 'AirbridgeNative') === undefined ? (
<button onClick={() => {
openDeeplink(new URL(`${context.app}://deeplink`)!)
}}>Open Deeplink</button>
) : undefined }
</header>
</div>
) : (
<div className="App">
<header className="App-header">
<p>Airbridge Web Example (Select)</p>
<button onClick={() => {
window.location.search = '?app=exabr'
}}>exabr</button>
</header>
</div>
)
}
export default App