-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathApp.js
More file actions
executable file
·139 lines (131 loc) · 5.51 KB
/
App.js
File metadata and controls
executable file
·139 lines (131 loc) · 5.51 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React, { useState, useEffect, Suspense } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { ApolloProvider } from '@apollo/client'
import { Route, Navigate, Routes } from 'react-router-dom'
import routeConfig from './routes'
import apolloClient from './graphql/client'
import config from 'constants/config'
import * as AuthSelectors from 'reducers/auth/selectors'
import * as AuthActions from 'reducers/auth/actions'
import AnalyticsService from 'services/analytics'
import { getCookieConsentValue } from 'react-cookie-consent'
import CookieConsentBar from 'components/layouts/CookieConsentBar'
import * as SnackbarActions from 'reducers/snackbar/actions'
export default ({ location }) => {
const dispatch = useDispatch()
const idToken = useSelector(AuthSelectors.getIdToken)
const isAuthenticated = useSelector(AuthSelectors.isAuthenticated)
const isSessionExpired = useSelector(AuthSelectors.isSessionExpired)
const [loading, setLoading] = useState(true)
useEffect(() => {
if (getCookieConsentValue() === 'true') {
AnalyticsService.init()
AnalyticsService.pageView(window.location)
/**
const unlisten = history.listen(AnalyticsService.pageView)
return () => {
unlisten()
}
*/
}
}, [location])
useEffect(() => {
setLoading(false)
if (isAuthenticated && isSessionExpired) {
setLoading(true)
console.log('renewing session now')
try {
dispatch(AuthActions.renewSession())
} catch (err) {
console.log(err)
dispatch(SnackbarActions.error('Please, log in again'))
} finally {
setLoading(false)
}
}
}, [dispatch, isAuthenticated, isSessionExpired])
return (
<ApolloProvider
client={
apolloClient(
idToken,
) /*TODO: fails to fetch when renewing session causing a loop. fix! */
}
>
<Suspense fallback={null}>
{!loading && (
<Routes>
{routeConfig.routes.map(route => (
<Route key={route.path} {...route} />
))}
{/**
* Miscellaneous
* TODO: 404 page
*/}
<title>{config.PLATFORM_OWNER_NAME}</title>
<meta
name="keywords"
content="Hackathon, hackathon platform, Junction"
/>
<meta
name="title"
content={config.SEO_PAGE_TITLE}
/>
<meta
property="og:title"
content={config.SEO_PAGE_TITLE}
/>
<meta
name="twitter:title"
content={config.SEO_PAGE_TITLE}
/>
<meta
name="description"
content={config.SEO_PAGE_DESCRIPTION}
/>
<meta
property="og:description"
content={config.SEO_PAGE_DESCRIPTION}
/>
<meta
name="twitter:description"
content={config.SEO_PAGE_DESCRIPTION}
/>
<meta name="og:type" content="website" />
<meta
property="og:image"
content={config.SEO_IMAGE_URL}
/>
<meta
name="twitter:image"
content={config.SEO_IMAGE_URL}
/>
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta
name="twitter:card"
content="summary_large_image"
/>
<meta
name="twitter:site"
content={config.SEO_TWITTER_HANDLE}
/>
<meta
name="twitter:creator"
content={config.SEO_TWITTER_HANDLE}
/>
<script
type="text/javascript"
async
src="https://platform.twitter.com/widgets.js"
></script>
{/* {isAuthenticated ?
<Navigate to="/dashboard" /> :} */}
<Navigate to="/" />
</Routes>
)}
</Suspense>
<CookieConsentBar />
</ApolloProvider>
)
}