Site > Chat > Add unread count

This commit is contained in:
brunosimon
2017-08-15 01:59:35 +02:00
parent 92d996731a
commit ff4b555c64
2 changed files with 20 additions and 2 deletions
+19 -1
View File
@@ -7,7 +7,8 @@ export default
return { return {
userName: '', userName: '',
messageText: '', messageText: '',
open: false open: false,
unreadCount: 0
} }
}, },
@@ -33,6 +34,11 @@ export default
messages() messages()
{ {
if(!this.atBottom || !this.open)
{
this.unreadCount++
}
window.requestAnimationFrame(() => window.requestAnimationFrame(() =>
{ {
if(this.atBottom) if(this.atBottom)
@@ -59,6 +65,12 @@ export default
onHeaderClick() onHeaderClick()
{ {
this.open = !this.open this.open = !this.open
// Reset unread count
if(this.open)
{
this.unreadCount = 0
}
}, },
onUserNameChange() onUserNameChange()
@@ -91,6 +103,12 @@ export default
onMessagesScroll() onMessagesScroll()
{ {
this.atBottom = this.$messages.scrollTop + this.$messages.offsetHeight >= this.$innerMessages.offsetHeight - 15 this.atBottom = this.$messages.scrollTop + this.$messages.offsetHeight >= this.$innerMessages.offsetHeight - 15
// Reset unread count
if(this.atBottom)
{
this.unreadCount = 0
}
} }
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
<div class="chat"> <div class="chat">
<header class="header" @click="onHeaderClick"> <header class="header" @click="onHeaderClick">
Discussions Discussions ({{ unreadCount }})
</header> </header>
<div class="content" v-show="open"> <div class="content" v-show="open">
<div class="messages" @scroll="onMessagesScroll"> <div class="messages" @scroll="onMessagesScroll">