This repository has been archived by the owner on Jun 10, 2021. It is now read-only.
/
main.js
108 lines (89 loc) · 3.1 KB
/
main.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
import './project/polyfil';
import './project/libs';
import './project/api';
import './project/project-components';
import './styles/styles.scss';
import { BrowserRouter as Router } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import ToastMessages from './project/toast';
import routes from './routes';
import AccountStore from '../common/stores/account-store';
import data from '../common/data/base/_data';
window.Project = require('../common/project');
window.Project = {
...window.Project,
...projectOverrides, // environment.js (also app.yaml if using app engine)
};
window.Utils = require('../common/utils/utils');
window.Constants = require('../common/constants');
window.openModal = require('./project/modals').openModal;
window.openConfirm = require('./project/modals').openConfirm;
const rootElement = document.getElementById('app');
const params = Utils.fromParam();
if (params.token) {
API.setCookie('t', params.token);
document.location = document.location.origin;
}
function hashLinkScroll() {
const { hash } = window.location;
if (hash !== '') {
// Push onto callback queue so it runs after the DOM is updated,
// this is required when navigating from a different page so that
// the element is rendered on the page before trying to getElementById.
setTimeout(() => {
const id = hash.replace('#', '');
const element = document.getElementById(id);
if (element) element.scrollIntoView({ behavior: 'smooth' });
}, 0);
}
}
// Render the React application to the DOM
const res = API.getCookie('t');
const event = API.getEvent();
if (event) {
try {
data.post('/api/event', JSON.parse(event))
.catch(() => {})
.finally(() => {
API.setEvent('');
});
} catch (e) {
}
}
const isInvite = document.location.href.includes('invite');
if (res && !isInvite) {
AppActions.setToken(res);
}
setTimeout(() => {
const browserHistory = createBrowserHistory();
// redirect before login
// todo: move to util to decide if url is public
if (
(document.location.pathname.indexOf('/project/') !== -1
|| document.location.pathname.indexOf('/create') !== -1
|| document.location.pathname.indexOf('/invite') !== -1
|| document.location.pathname.indexOf('/projects') !== -1)
&& !AccountStore.getUser()) {
browserHistory.push(`/?redirect=${encodeURIComponent(document.location.pathname + (document.location.search || ''))}`);
}
ReactDOM.render(
<Router>{routes}</Router>,
rootElement,
);
}, 1);
// Setup for toast messages
ReactDOM.render(<ToastMessages/>, document.getElementById('toast'));
if (E2E) {
document.body.classList.add('disable-transitions');
}
if (!E2E && Project.crispChat) {
window.$crisp = [];
window.CRISP_WEBSITE_ID = Project.crispChat;
(function () {
const d = document;
const s = d.createElement('script');
s.src = 'https://client.crisp.chat/l.js';
s.async = 1;
d.getElementsByTagName('head')[0].appendChild(s);
}());
}