2016-06-01 10:29:15 +05:30
|
|
|
import 'polyfills';
|
2016-01-03 01:54:07 +05:30
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
|
|
|
|
import { Provider as ReduxProvider } from 'react-redux';
|
|
|
|
import { Router, browserHistory } from 'react-router';
|
|
|
|
|
2016-10-11 09:37:09 +05:30
|
|
|
import webFont from 'webfontloader';
|
|
|
|
|
2016-05-10 10:47:40 +05:30
|
|
|
import { factory as userFactory } from 'components/user/factory';
|
2016-05-20 01:11:43 +05:30
|
|
|
import { IntlProvider } from 'components/i18n';
|
2016-02-13 20:58:47 +05:30
|
|
|
import routesFactory from 'routes';
|
2016-06-18 20:30:45 +05:30
|
|
|
import storeFactory from 'storeFactory';
|
2016-07-30 00:59:27 +05:30
|
|
|
import bsodFactory from 'components/ui/bsod/factory';
|
2016-11-19 15:04:19 +05:30
|
|
|
import loader from 'services/loader';
|
2016-12-07 02:36:45 +05:30
|
|
|
import logger from 'services/logger';
|
|
|
|
|
|
|
|
logger.init({
|
|
|
|
sentryCdn: window.sentryCdn
|
|
|
|
});
|
2016-01-03 01:54:07 +05:30
|
|
|
|
2016-06-18 20:30:45 +05:30
|
|
|
const store = storeFactory();
|
2016-01-03 01:54:07 +05:30
|
|
|
|
2016-07-30 00:59:27 +05:30
|
|
|
bsodFactory(store, stopLoading);
|
|
|
|
|
2016-10-11 09:37:09 +05:30
|
|
|
const fontLoadingPromise = new Promise((resolve) =>
|
|
|
|
webFont.load({
|
|
|
|
classes: false,
|
|
|
|
active: resolve,
|
|
|
|
inactive: resolve, // TODO: may be we should track such cases
|
|
|
|
timeout: 2000,
|
|
|
|
custom: {
|
|
|
|
families: ['Roboto', 'Roboto Condensed']
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
Promise.all([
|
|
|
|
userFactory(store),
|
|
|
|
fontLoadingPromise
|
|
|
|
])
|
2016-05-20 01:11:43 +05:30
|
|
|
.then(() => {
|
2016-05-10 10:47:40 +05:30
|
|
|
ReactDOM.render(
|
2016-05-20 01:11:43 +05:30
|
|
|
<ReduxProvider store={store}>
|
|
|
|
<IntlProvider>
|
2016-06-02 23:16:49 +05:30
|
|
|
<Router history={browserHistory} onUpdate={() => {
|
|
|
|
restoreScroll();
|
|
|
|
stopLoading();
|
|
|
|
}}>
|
2016-05-10 10:47:40 +05:30
|
|
|
{routesFactory(store)}
|
|
|
|
</Router>
|
2016-05-20 01:11:43 +05:30
|
|
|
</IntlProvider>
|
|
|
|
</ReduxProvider>,
|
2016-05-10 10:47:40 +05:30
|
|
|
document.getElementById('app')
|
|
|
|
);
|
|
|
|
});
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2016-10-11 09:37:09 +05:30
|
|
|
|
|
|
|
function stopLoading() {
|
2016-11-19 15:04:19 +05:30
|
|
|
loader.hide();
|
2016-10-11 09:37:09 +05:30
|
|
|
}
|
|
|
|
|
2016-06-04 02:21:45 +05:30
|
|
|
import scrollTo from 'components/ui/scrollTo';
|
2016-06-04 01:50:56 +05:30
|
|
|
const SCROLL_ANCHOR_OFFSET = 80; // 50 + 30 (header height + some spacing)
|
2016-05-31 10:20:22 +05:30
|
|
|
/**
|
|
|
|
* Scrolls to page's top or #anchor link, if any
|
|
|
|
*/
|
|
|
|
function restoreScroll() {
|
|
|
|
const {hash} = location;
|
|
|
|
|
|
|
|
// Push onto callback queue so it runs after the DOM is updated
|
|
|
|
setTimeout(() => {
|
|
|
|
const id = hash.replace('#', '');
|
|
|
|
const el = id ? document.getElementById(id) : null;
|
2016-06-04 13:09:24 +05:30
|
|
|
const viewPort = document.getElementById('view-port');
|
|
|
|
|
|
|
|
if (!viewPort) {
|
2016-07-29 23:25:19 +05:30
|
|
|
console.log('Can not find viewPort element');
|
|
|
|
return;
|
2016-06-04 13:09:24 +05:30
|
|
|
}
|
2016-06-04 01:50:56 +05:30
|
|
|
|
|
|
|
let y = 0;
|
2016-05-31 10:20:22 +05:30
|
|
|
if (el) {
|
2016-06-04 13:09:24 +05:30
|
|
|
const {scrollTop} = viewPort;
|
2016-06-04 01:50:56 +05:30
|
|
|
const {top} = el.getBoundingClientRect();
|
|
|
|
|
|
|
|
y = scrollTop + top - SCROLL_ANCHOR_OFFSET;
|
2016-05-31 10:20:22 +05:30
|
|
|
}
|
2016-06-04 01:50:56 +05:30
|
|
|
|
2016-06-04 13:09:24 +05:30
|
|
|
scrollTo(y, viewPort);
|
2016-08-14 14:31:04 +05:30
|
|
|
}, 200);
|
2016-05-31 10:20:22 +05:30
|
|
|
}
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2016-11-20 17:31:57 +05:30
|
|
|
browserHistory.listen(trackPageView);
|
|
|
|
|
|
|
|
function trackPageView(location) {
|
|
|
|
const ga = window.ga;
|
|
|
|
|
|
|
|
if (!ga) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ga('set', 'page', location.pathname + location.search);
|
|
|
|
ga('send', 'pageview');
|
|
|
|
}
|
|
|
|
|
2016-06-04 14:47:06 +05:30
|
|
|
/* global process: false */
|
2016-04-12 09:19:58 +05:30
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
// some shortcuts for testing on localhost
|
2016-11-19 20:11:15 +05:30
|
|
|
window.testOAuth = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&login_hint=${loginHint}`;
|
|
|
|
window.testOAuthPromptAccount = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account';
|
|
|
|
window.testOAuthPromptPermissions = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=consent&login_hint=${loginHint}`;
|
|
|
|
window.testOAuthPromptAll = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account,consent';
|
2016-10-25 12:02:50 +05:30
|
|
|
window.testOAuthStatic = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page_with_code&response_type=code&scope=account_info%2Caccount_email';
|
|
|
|
window.testOAuthStaticCode = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=static_page&response_type=code&scope=account_info%2Caccount_email';
|
2016-08-14 14:27:15 +05:30
|
|
|
|
|
|
|
// expose Perf
|
|
|
|
window.Perf = require('react-addons-perf');
|
2016-04-12 09:19:58 +05:30
|
|
|
}
|