-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.tsx
78 lines (72 loc) · 2.93 KB
/
client.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
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import App from './src/App';
import * as AxiosHooks from "axios-hooks";
import {Provider} from "react-redux";
import {createStore} from "redux";
import {IApplicationState} from "./src/store/Models";
import appReducer, {initialState} from "./src/store/Reducer";
import {FGCProvider, Event, Team, Match, MatchParticipant, getRankingBySeasonKey} from "@the-orange-alliance/lib-ems";
// Dealing with our application caches -- Axios and Redux
(AxiosHooks as any).loadCache((window as any).__AXIOS_HOOKS_CACHE__);
delete (window as any).__AXIOS_HOOKS_CACHE__;
const stateCache = (window as any).__REDUX_STATE_CACHE__;
delete (window as any).__REDUX_STATE_CACHE__;
const isDev: boolean = true;
FGCProvider.initialize("theorangealliance.org", 9443 , 'https');
// FGCProvider.initialize("127.0.0.1", 8080);
let state: IApplicationState = stateCache;
if (stateCache.length > 0 && stateCache[0] === "__REDUX__") {
state = initialState;
} else {
if (state.completeMatch) {
state.completeMatch = new Match().fromJSON(state.completeMatch);
}
if (state.completeTeam) {
state.completeTeam.team = new Team().fromJSON(state.completeTeam.team);
state.completeTeam.matches = state.completeTeam.matches.map((matchJSON: any) => {
const participants: MatchParticipant[] = typeof matchJSON.participants !== "undefined" ? matchJSON.participants.map((p: any) => new MatchParticipant().fromJSON(p)) : [];
const match: Match = new Match().fromJSON(matchJSON);
match.participants = participants;
return match;
});
state.completeTeam.rankings = state.completeTeam.rankings.map((r: any) => getRankingBySeasonKey(r.rank_key.split("-")[0]).fromJSON(r));
}
if (state.teams && state.teams.length > 0) {
state.teams = state.teams.map((t: any) => new Team().fromJSON(t));
}
if (state.rankings && state.rankings.length > 0) {
state.rankings = state.rankings.map((r: any) => getRankingBySeasonKey(r.rank_key.split("-")[0]).fromJSON(r));
}
if (state.matches && state.matches.length > 0) {
state.matches = state.matches.map((matchJSON: any) => {
const participants: MatchParticipant[] = typeof matchJSON.participants !== "undefined" ? matchJSON.participants.map((p: any) => new MatchParticipant().fromJSON(p)) : [];
const match: Match = new Match().fromJSON(matchJSON);
match.participants = participants;
return match;
});
}
if (state.event) {
state.event = new Event().fromJSON(state.event);
}
}
if (isDev) {
ReactDOM.render(
<Provider store={createStore(appReducer, state)}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>,
document.getElementById('app')
);
} else {
ReactDOM.hydrate(
<Provider store={createStore(appReducer, state)}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>,
document.getElementById('app')
);
}