feat(chat): usage improvements with hooks
1. scroll room messages to the bottom 2. submit message on `enter`
This commit is contained in:
14
assets/js/hooks/ChatMessageTextarea.js
Normal file
14
assets/js/hooks/ChatMessageTextarea.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const ChatMessageTextarea = {
|
||||
mounted() {
|
||||
this.el.addEventListener('keydown', e => {
|
||||
if (e.key == 'Enter' && !e.shitfKey) {
|
||||
const form = document.getElementById('new-message-form');
|
||||
|
||||
form.dispatchEvent(new Event('change', { bubbles: true, cancelable: true }));
|
||||
form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default ChatMessageTextarea;
|
10
assets/js/hooks/RoomMessages.js
Normal file
10
assets/js/hooks/RoomMessages.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const RoomMessages = {
|
||||
mounted() {
|
||||
this.el.scrollTop = this.el.scrollHeight;
|
||||
this.handleEvent("scroll_messages_to_bottom", () => {
|
||||
this.el.scrollTop = this.el.scrollHeight;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default RoomMessages;
|
Reference in New Issue
Block a user