-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.jsx
73 lines (59 loc) · 1.88 KB
/
main.jsx
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
import React from 'react';
import {render} from 'react-dom';
import {Router, Route} from 'react-router';
import cookie from 'react-cookie';
import FloorPlan from './components/FloorPlan.jsx';
import RoomPage from './components/RoomPage.jsx';
import SetHomePage from './components/SetHomePage.jsx';
import RoomActionCreators from './actions/RoomActionCreators.js';
import GoogleApi from './GoogleApi';
import GoogleApiInit from './GoogleApiInit.jsx';
require('./scss/index.scss');
const MINUTE_DELAY_BEFORE_HOME_PAGE_REDIRECT = 10;
let CURRENT_TIMEOUT_ID;
function redirectToHome() {
const homePath = cookie.load('home');
if (homePath && !document.location.hash.startsWith(homePath)) {
console.log(`redirect to ${homePath}`);
document.location = homePath;
}
}
function redirectToHomeTimeout() {
console.log(`set redirect timeout to ${MINUTE_DELAY_BEFORE_HOME_PAGE_REDIRECT} minutes`);
clearTimeout(CURRENT_TIMEOUT_ID);
CURRENT_TIMEOUT_ID = setTimeout(
redirectToHome,
1000 * 60 * MINUTE_DELAY_BEFORE_HOME_PAGE_REDIRECT
);
}
function fetchRoomsLoop() {
RoomActionCreators.fetchRooms();
RoomActionCreators.updateTime();
const oneMinute = 1000 * 60;
setInterval(
RoomActionCreators.fetchRooms,
oneMinute
);
setInterval(
RoomActionCreators.updateTime,
oneMinute
);
}
function initApp(googleClient) {
GoogleApi.initClient(googleClient);
fetchRoomsLoop();
render(
(
<Router>
<Route path="/" component={FloorPlan} onEnter={redirectToHomeTimeout} />
<Route path="rooms/:roomId" component={RoomPage} onEnter={redirectToHomeTimeout}/>
<Route path="sethome" component={SetHomePage} />
</Router>
),
document.getElementById('bookit')
);
}
export default {
initApp,
GoogleApiInit,
};