Skip to content

Commit

Permalink
feat: open chat is recipientId is present in the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulov1337 committed Dec 17, 2024
1 parent 0e1063e commit d486a66
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/pages/ChatPage/ChatPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import BaseComponent from '../../components/BaseComponent/BaseComponent';
import ChatWindow from '../../components/ChatWindow/ChatWindow';
import ApiClient from '../../modules/ApiClient';
import ChatRepository, { Chat } from '../../repositories/ChatRepository';

export default class ChatPage extends BaseComponent {
Expand All @@ -18,21 +19,31 @@ export default class ChatPage extends BaseComponent {
if (!startChatWithRecipientId) return;

requestAnimationFrame(async () => {
// const data = await ChatRepository.get(startChatWithRecipientId);
// const chatWindow = new ChatWindow(
// this.thisElement,
// startChatWithRecipientId,
// data
// );
// chatWindow.on('new-message', (message) => {
// if (typeof message === 'string')
// (
// document.getElementById(
// `recipient-${el.dataset.id}-last-message`
// ) as HTMLElement
// ).textContent = message;
// });
// chatWindow.render();
const data = await ChatRepository.get(startChatWithRecipientId);
const recipientName = (
await ApiClient.getUser(startChatWithRecipientId)
)['name'];

const chatWindow = new ChatWindow(
this.thisElement,
startChatWithRecipientId,
recipientName,
data
);

document
.getElementById(`recipient-${startChatWithRecipientId}`)
?.classList.add('recipient-card--active');

chatWindow.on('new-message', (message) => {
if (typeof message === 'string')
(
document.getElementById(
`recipient-${startChatWithRecipientId}-last-message`
) as HTMLElement
).textContent = message;
});
chatWindow.render();
});
}

Expand Down

0 comments on commit d486a66

Please sign in to comment.