docbrown/app/javascript/packs/Onboarding.jsx
Nick Taylor 24621b03f2 Restructure pack files part I (#377)
* Renamed pack file from chat.jsx to Chat.jsx.

* refactor

* Missed a js pack where chat.js -> Chat.jsx

* 👷Refactor

* 👷Refactor

* 👷Refactor

* 👷Refactor

* Tests

* Fixed some wording in a test description.
2018-08-29 12:59:20 -04:00

48 lines
1.2 KiB
JavaScript

import { h, render } from 'preact';
import { getUserDataAndCsrfToken } from '../chat/util';
import getUnopenedChannels from '../src/utils/getUnopenedChannels';
HTMLDocument.prototype.ready = new Promise(resolve => {
if (document.readyState !== 'loading') {
return resolve();
}
document.addEventListener('DOMContentLoaded', () => resolve());
return null;
});
function isUserSignedIn() {
return (
document.head.querySelector(
'meta[name="user-signed-in"][content="true"]',
) !== null
);
}
function renderPage() {
import('../src/Onboarding')
.then(({ default: Onboarding }) =>
render(<Onboarding />, document.getElementById('top-bar')),
)
.catch(error => {
// eslint-disable-next-line no-console
console.error('Unable to load onboarding', error);
});
}
document.ready.then(
getUserDataAndCsrfToken()
.then(({ currentUser, csrfToken }) => {
window.currentUser = currentUser;
window.csrfToken = csrfToken;
getUnopenedChannels();
if (isUserSignedIn() && !currentUser.saw_onboarding) {
renderPage();
}
})
.catch(error => {
// eslint-disable-next-line no-console
console.error('Error getting user and CSRF Token', error);
}),
);