accounts-frontend/src/index.js

81 lines
3.4 KiB
JavaScript
Raw Normal View History

import 'polyfills';
2019-11-09 22:56:46 +05:30
import 'react-hot-loader';
import React from 'react';
import ReactDOM from 'react-dom';
import { factory as userFactory } from 'components/user/factory';
import authFlow from 'services/authFlow';
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';
import loader from 'services/loader';
import logger from 'services/logger';
2017-01-25 11:22:19 +05:30
import font from 'services/font';
import history, { browserHistory } from 'services/history';
2019-11-09 22:56:46 +05:30
import { loadScript, debounce } from 'functions';
import App from './App';
history.init();
logger.init({
sentryCdn: window.SENTRY_CDN
});
2016-06-18 20:30:45 +05:30
const store = storeFactory();
bsodFactory(store, () => loader.hide());
authFlow.setStore(store);
2016-07-30 00:59:27 +05:30
Promise.all([
userFactory(store),
2017-01-25 11:22:19 +05:30
font.load(['Roboto', 'Roboto Condensed'])
2019-11-09 22:56:46 +05:30
]).then(() => {
ReactDOM.render(
<App store={store} browserHistory={browserHistory} />,
document.getElementById('app')
);
2019-11-09 22:56:46 +05:30
initAnalytics();
});
const trackPageView = debounce(_trackPageView);
function initAnalytics() {
if (!window.ga) {
const ga = window.ga = function() {
(ga.q = ga.q || []).push(arguments); // eslint-disable-line
};
ga.l = Date.now(); // eslint-disable-line
if (window.GA_ID) {
// when GA is not available, we will continue to push into array
// for debug purposes
// Catch to prevent "unhandled rejection" error
loadScript('https://www.google-analytics.com/analytics.js').catch(() => {});
}
2016-11-20 17:31:57 +05:30
ga('create', window.GA_ID, 'auto');
trackPageView(location);
2016-11-20 17:31:57 +05:30
browserHistory.listen(trackPageView);
2016-11-20 17:31:57 +05:30
}
}
function _trackPageView(location) {
const ga = window.ga;
2016-11-20 17:31:57 +05:30
ga('set', 'page', location.pathname + location.search);
ga('send', 'pageview');
}
/* global process: false */
if (process.env.NODE_ENV !== 'production') {
// some shortcuts for testing on localhost
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.testOAuthPermissions = () => location.href = '/oauth2/v1/tlauncher?client_id=tlauncher&redirect_uri=http%3A%2F%2Flocalhost%3A8080&response_type=code&scope=account_info,account_email';
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';
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';
}