Skip to content

Commit

Permalink
feat(MessagesList): Make dateSep sticky
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <dorra.jaoued7@gmail.com>
  • Loading branch information
DorraJaouad committed Feb 27, 2024
1 parent 241cf97 commit 4f22e26
Showing 1 changed file with 58 additions and 8 deletions.
66 changes: 58 additions & 8 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ get the messagesList array and loop through the list to generate the messages.
<div ref="scroller"
:key="token"
class="scroller messages-list__scroller"
:class="{'scroller--chatScrolledToBottom': isChatScrolledToBottom}"
@scroll="debounceHandleScroll">
:class="{'scroller--chatScrolledToBottom': isChatScrolledToBottom,
'scroller--isScrolling': isScrolling}"
@scroll="onScroll"
@scrollend="endScroll">
<div v-if="displayMessagesLoader" class="scroller__loading icon-loading" />

<ul v-for="(list, dateTimestamp) in messagesGroupedByDateByAuthor"
:key="`section_${dateTimestamp}`"
class="dates-group-wrapper">
<li :key="dateTimestamp" class="messages-group__date">
:ref="`dateGroup-${token}`"
:data-date-timestamp="dateTimestamp"
:class="{'has-sticky': dateTimestamp === stickyDate}">
<li class="messages-group__date">
<span class="messages-group__date-text" role="heading" aria-level="3">
{{ dateSeparatorLabels[dateTimestamp] }}
</span>
Expand Down Expand Up @@ -138,7 +142,6 @@ export default {
/**
* A list of messages grouped by same day and then by author and time.
*/

messagesGroupedByDateByAuthor: {},

viewId: null,
Expand Down Expand Up @@ -888,6 +891,38 @@ export default {
}, 500)
},

checkSticky() {
const ulElements = this.$refs['dateGroup-' + this.token]
if (!ulElements) {
return
}

const scrollerRect = this.$refs.scroller.getBoundingClientRect()
ulElements.forEach((element) => {
const rect = element.getBoundingClientRect()
if (rect.top <= scrollerRect.top && rect.bottom >= scrollerRect.top) {
this.stickyDate = element.getAttribute('data-date-timestamp')
}
})
},

onScroll() {
// handle scrolling status
if (this.isScrolling) {
clearTimeout(this.endScrollTimeout)
}
this.isScrolling = true
this.endScrollTimeout = setTimeout(this.endScroll, 3000)
// handle sticky date
if (this.$refs.scroller.scrollTop === 0) {
this.stickyDate = null
} else {
this.checkSticky()
}
// handle scroll event
this.debounceHandleScroll()
},

/**
* When the div is scrolled, this method checks if it's been scrolled to the top
* or to the bottom of the list bottom.
Expand Down Expand Up @@ -952,6 +987,11 @@ export default {
this.debounceUpdateReadMarkerPosition()
},

endScroll() {
this.isScrolling = false
clearTimeout(this.endScrollTimeout)
},

/**
* Finds the last message that is fully visible in the scroller viewport
*
Expand Down Expand Up @@ -1303,11 +1343,10 @@ export default {

&__loading {
position: absolute;
top: 10px;
top: 17px;
left: 50%;
height: 40px;
width: 40px;
transform: translatex(-64px);
transform: translatex(-380px);
}
}

Expand Down Expand Up @@ -1341,4 +1380,15 @@ export default {
margin-bottom: 16px;
}
}

.has-sticky .messages-group__date {
transition: opacity 0.3s ease-in-out;
transition-delay: 2s;
opacity: 0;
}

.scroller--isScrolling .has-sticky .messages-group__date {
opacity: 1;
transition: opacity 0s;
}
</style>

0 comments on commit 4f22e26

Please sign in to comment.