accounts-frontend/src/index.js

78 lines
2.5 KiB
JavaScript
Raw Normal View History

import 'polyfills';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider as ReduxProvider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { factory as userFactory } from 'components/user/factory';
2016-05-20 01:11:43 +05:30
import { IntlProvider } from 'components/i18n';
import routesFactory from 'routes';
2016-06-18 20:30:45 +05:30
import storeFactory from 'storeFactory';
2016-06-18 20:30:45 +05:30
const store = storeFactory();
userFactory(store)
2016-05-20 01:11:43 +05:30
.then(() => {
// allow :active styles in mobile Safary
2016-06-18 20:30:45 +05:30
document.addEventListener('touchstart', () => {}, true);
ReactDOM.render(
2016-05-20 01:11:43 +05:30
<ReduxProvider store={store}>
<IntlProvider>
<Router history={browserHistory} onUpdate={() => {
restoreScroll();
stopLoading();
}}>
{routesFactory(store)}
</Router>
2016-05-20 01:11:43 +05:30
</IntlProvider>
</ReduxProvider>,
document.getElementById('app')
);
});
2016-06-04 02:21:45 +05:30
import scrollTo from 'components/ui/scrollTo';
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;
const viewPort = document.getElementById('view-port');
if (!viewPort) {
2016-07-29 23:25:19 +05:30
console.log('Can not find viewPort element');
return;
}
let y = 0;
2016-05-31 10:20:22 +05:30
if (el) {
const {scrollTop} = viewPort;
const {top} = el.getBoundingClientRect();
y = scrollTop + top - SCROLL_ANCHOR_OFFSET;
2016-05-31 10:20:22 +05:30
}
scrollTo(y, viewPort);
2016-05-31 10:20:22 +05:30
}, 100);
}
function stopLoading() {
document.getElementById('loader').classList.remove('is-active');
}
/* global process: false */
if (process.env.NODE_ENV !== 'production') {
// some shortcuts for testing on localhost
2016-07-28 01:15:50 +05:30
window.testOAuth = () => location.href = '/oauth2/v1?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session';
window.testOAuthStatic = () => location.href = '/oauth2/v1?client_id=ely&redirect_uri=static_page_with_code&response_type=code&scope=minecraft_server_session';
window.testOAuthStaticCode = () => location.href = '/oauth2/v1?client_id=ely&redirect_uri=static_page&response_type=code&scope=minecraft_server_session';
}