-
Notifications
You must be signed in to change notification settings - Fork 13
/
client.js
123 lines (106 loc) · 3.24 KB
/
client.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
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
import React from "react";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import { isReactComponents } from "./lib/utils";
import "./startup/client/index.js";
import About from "./ui/components/About.jsx";
import Admin from "./ui/components/Admin.jsx";
import Centered from "./ui/components/Centered.jsx";
import Consent, { ConsentButton } from "./ui/components/Consent.jsx";
import Login from "./ui/components/Login.jsx";
import NewPlayer from "./ui/components/NewPlayer.jsx";
import NoBatch from "./ui/components/NoBatch";
import StageTimeWrapper from "./ui/components/StageTimeWrapper.jsx";
import { AlertToaster } from "./ui/components/Toasters.jsx";
import AuthorizedContainer from "./ui/containers/AuthorizedContainer.jsx";
import IdentifiedContainer from "./ui/containers/IdentifiedContainer.jsx";
import PublicContainer from "./ui/containers/PublicContainer.jsx";
const config = {
exitSteps: () => [],
introSteps: () => []
};
const Empirica = {
about(AboutComp) {
config.About = AboutComp || About;
},
noBatch(NoBatchComp) {
config.NoBatch = NoBatchComp || NoBatch;
},
consent(ConsentComp) {
config.Consent = ConsentComp || Consent;
},
newPlayer(NewPlayerComp) {
config.NewPlayer = NewPlayerComp || NewPlayer;
},
round(RoundComp) {
config.Round = RoundComp;
},
header(HeaderComp) {
config.Header = HeaderComp;
},
// gameLobby, treatment, player
lobby(LobbyComp) {
config.Lobby = LobbyComp;
},
breadcrumb(BreadcrumbComp) {
config.Breadcrumb = BreadcrumbComp;
},
waiting(WaitingComp) {
config.Waiting = WaitingComp;
},
introSteps(func) {
if (!_.isFunction(func)) {
throw new Error("Empirica.introSteps() requires a function");
}
config.introSteps = function() {
const results = func.apply(null, arguments);
if (!results || isReactComponents(results)) {
return results || [];
} else {
console.error(
"Empirica.introSteps() is not returning an array of components as expected."
);
return [];
}
};
},
exitSteps(func) {
if (!_.isFunction(func)) {
throw new Error("Empirica.exitSteps() requires a function");
}
config.exitSteps = function() {
const results = func.apply(null, arguments);
if (!results || isReactComponents(results)) {
return results || [];
} else {
console.error(
"Empirica.exitSteps() is not returning an array of components as expected."
);
return [];
}
};
},
routes() {
return (
<BrowserRouter>
<div className="app">
<Switch>
<Route path="/" exact component={this.appComp()} />
<Route path="/admin" component={this.adminComp()} />
<Route path="/login" component={this.loginComp()} />
</Switch>
</div>
</BrowserRouter>
);
},
appComp() {
return IdentifiedContainer(PublicContainer, config);
},
adminComp({ loginPath = "/login" } = {}) {
return AuthorizedContainer(Admin, { loginPath });
},
loginComp({ adminPath = "/admin" } = {}) {
return AuthorizedContainer(Login, { adminPath });
}
};
export default Empirica;
export { StageTimeWrapper, Centered, AlertToaster, ConsentButton };