-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable shortpolling for updating chat list
- Loading branch information
1 parent
d486a66
commit aaf21a3
Showing
5 changed files
with
134 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div | ||
class='recipient-card' | ||
data-id='{{author.id}}' | ||
data-name='{{author.name}}' | ||
id='{{id}}' | ||
> | ||
<img class='recipient-card__avatar' src='{{author.avatar}}' /> | ||
<div class='recipient-card__info'> | ||
<p class='recipient-card__name'>{{author.name}}</p> | ||
<p | ||
class='recipient-card__text' | ||
id='recipient-{{author.id}}-last-message' | ||
>{{lastMessage}}</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import ChatRepository from '../../repositories/ChatRepository'; | ||
import BaseComponent from '../BaseComponent/BaseComponent'; | ||
import ChatWindow from '../ChatWindow/ChatWindow'; | ||
|
||
export default class ChatRecipientCard extends BaseComponent { | ||
private authorInfo: { | ||
name: string; | ||
id: string; | ||
avatar: string; | ||
}; | ||
private lastMessage: string; | ||
|
||
constructor( | ||
parent: HTMLElement, | ||
id: string, | ||
authorInfo: { | ||
name: string; | ||
id: string; | ||
avatar: string; | ||
}, | ||
lastMessage: string | ||
) { | ||
super({ | ||
parent: parent, | ||
id: id, | ||
templateName: 'ChatRecipientCard', | ||
templateData: { | ||
author: authorInfo, | ||
lastMessage: lastMessage, | ||
}, | ||
}); | ||
|
||
this.authorInfo = authorInfo; | ||
this.lastMessage = lastMessage; | ||
} | ||
|
||
protected addEventListeners(): void { | ||
this.thisElement.onclick = async () => { | ||
// Remove active class from already selected chat list item | ||
document | ||
.querySelector('.recipient-card--active') | ||
?.classList.remove('recipient-card--active'); | ||
|
||
this.thisElement.classList.add('recipient-card--active'); | ||
|
||
// Remove old Chat Window if present | ||
document.getElementById('ChatWindow-0')?.remove(); | ||
|
||
// Create new Chat Window | ||
const data = await ChatRepository.get(this.authorInfo.id); | ||
const chatWindow = new ChatWindow( | ||
document.getElementById('ChatPage-')!, | ||
this.authorInfo.id, | ||
this.authorInfo.name, | ||
data | ||
); | ||
|
||
chatWindow.on('new-message', (message) => { | ||
if (typeof message !== 'string') return; | ||
( | ||
document.getElementById( | ||
`recipient-${this.authorInfo.id}-last-message` | ||
) as HTMLElement | ||
).textContent = message; | ||
}); | ||
|
||
chatWindow.render(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
<div class='chat-page' id='{{id}}'> | ||
<div class='recipients-list'> | ||
{{#each chats}} | ||
<div | ||
class='recipient-card' | ||
data-id='{{this.authorUuid}}' | ||
data-name='{{this.authorName}}' | ||
id='recipient-{{this.authorUuid}}' | ||
> | ||
<img | ||
class='recipient-card__avatar' | ||
src='{{this.authorAvatar}}' | ||
/> | ||
<div class='recipient-card__info'> | ||
<p class='recipient-card__name'>{{this.authorName}}</p> | ||
<p | ||
class='recipient-card__text' | ||
id='recipient-{{this.authorUuid}}-last-message' | ||
>{{this.lastMessage}}</p> | ||
</div> | ||
</div> | ||
{{/each}} | ||
<div class='recipients-list' id='recipients-list'> | ||
{{#each chats}}{{/each}} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters