docbrown/app/javascript/packs/chat.jsx
Ben Halpern 87c6a758bb
Add top bar indicator and other Connect features (#424)
* Add algolia public search key

* Add status to chat_channels
2018-06-12 18:24:57 -04:00

39 lines
1.1 KiB
JavaScript

import { h, render } from 'preact';
import { getUserDataAndCsrfToken } from '../chat/util';
import Chat from '../chat/chat';
HTMLDocument.prototype.ready = new Promise(resolve => {
if (document.readyState !== 'loading') {
return resolve();
}
document.addEventListener('DOMContentLoaded', () => resolve());
return null;
});
document.ready.then(
getUserDataAndCsrfToken().then(currentUser => {
if (document.getElementById('chat')) {
const { chatChannels, pusherKey, chatOptions, algoliaKey, algoliaId, algoliaIndex } = document.getElementById(
'chat',
).dataset;
window.currentUser = currentUser;
window.csrfToken = document.querySelector(
"meta[name='csrf-token']",
).content;
const root = render(
<Chat
pusherKey={pusherKey}
chatChannels={chatChannels}
chatOptions={chatOptions}
algoliaId={algoliaId}
algoliaKey={algoliaKey}
algoliaIndex={algoliaIndex}
/>,
document.getElementById('chat'),
);
window.InstantClick.on('change', () => {
render('', document.body, root);
});
}
}),
);