* Setup Pusher gem * Create ChatChannel and Message model * Create ChatChannelController * Add back fix-db-schema-conflicts gem * Add pusher-js package * Add validations on Message & ChatChannel models * Update Route * Create MessageController * Update ChatChannelController * Create Chat app WIP * Extract messenger render to Message Component * Implement live chat WIP * Implement live chat WIP (2) * Add style and scrollToBottom feature for chat * Create getUserDataAndCsrfToken function * Add feature toggle to the new live chat * Clean up ChatChannelsController & create spec * Update ChatChannel spec * Update Message spec * Create MessagesController spec & refactor * Clean up Chat app * Fix lint * Add character limit to Message
22 lines
769 B
JavaScript
22 lines
769 B
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());
|
|
});
|
|
|
|
document.ready
|
|
.then(getUserDataAndCsrfToken()
|
|
.then((currentUser) => {
|
|
if (document.getElementById('chat')) {
|
|
const { pusherKey } = document.getElementById('chat').dataset;
|
|
window.currentUser = currentUser;
|
|
window.csrfToken = document.querySelector("meta[name='csrf-token']").content;
|
|
render(
|
|
<Chat pusherKey={pusherKey} />,
|
|
document.getElementById('chat'),
|
|
);
|
|
}
|
|
}));
|