diff --git a/src/components/ChatWindow/ChatWindow.ts b/src/components/ChatWindow/ChatWindow.ts index d18abb00..af1a6c34 100644 --- a/src/components/ChatWindow/ChatWindow.ts +++ b/src/components/ChatWindow/ChatWindow.ts @@ -140,6 +140,8 @@ export default class ChatWindow extends BaseComponent { id: 0, createdAt: new Date().toISOString(), }); + + this.emit('new-message', text); } private handleMessageReceive(event: MessageEvent) { @@ -154,6 +156,7 @@ export default class ChatWindow extends BaseComponent { console.log(`[message] Данные получены с сервера: ${message}`); if ('content' in message) { + this.emit('new-message', message.content); this.addNewMessageElement(message); this.messagesContainer.scrollTop = diff --git a/src/pages/ChatPage/ChatPage.hbs b/src/pages/ChatPage/ChatPage.hbs index 777284c9..c07bcb7a 100644 --- a/src/pages/ChatPage/ChatPage.hbs +++ b/src/pages/ChatPage/ChatPage.hbs @@ -1,14 +1,21 @@
{{#each chats}} -
+

{{this.authorName}}

-

{{this.lastMessage}}

+

{{this.lastMessage}}

{{/each}} diff --git a/src/pages/ChatPage/ChatPage.ts b/src/pages/ChatPage/ChatPage.ts index eef8851c..8f4ee996 100644 --- a/src/pages/ChatPage/ChatPage.ts +++ b/src/pages/ChatPage/ChatPage.ts @@ -26,6 +26,15 @@ export default class ChatPage extends BaseComponent { data ); + // chatWindow.on('new-message', (message) => { + // if (typeof message === 'string') + // ( + // document.getElementById( + // `recipient-${el.dataset.id}-last-message` + // ) as HTMLElement + // ).textContent = message; + // }); + chatWindow.render(); }); } @@ -50,6 +59,15 @@ export default class ChatPage extends BaseComponent { data ); + chatWindow.on('new-message', (message) => { + if (typeof message === 'string') + ( + document.getElementById( + `recipient-${el.dataset.id}-last-message` + ) as HTMLElement + ).textContent = message; + }); + chatWindow.render(); }; }