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 21, 2024
1 parent e2e0315 commit fb4c381
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ 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"
Expand Down Expand Up @@ -174,6 +176,8 @@ export default {
debounceUpdateReadMarkerPosition: () => {},

debounceHandleScroll: () => {},

isScrolling: false,
}
},

Expand Down Expand Up @@ -859,6 +863,25 @@ export default {
}, 500)
},

checkSticky() {
const ulElements = this.$el.querySelectorAll('.dates-group-wrapper')
const scrollerRect = this.$refs.scroller.getBoundingClientRect()
ulElements.forEach((element) => {
const rect = element.getBoundingClientRect()
if (rect.top <= scrollerRect.top && rect.bottom >= scrollerRect.top) {
element.classList.add('has-sticky')
} else {
element.classList.remove('has-sticky')
}
})
},

onScroll() {
this.isScrolling = true
this.checkSticky()
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 @@ -923,6 +946,10 @@ export default {
this.debounceUpdateReadMarkerPosition()
},

endScroll() {
this.isScrolling = false
},

/**
* Finds the last message that is fully visible in the scroller viewport
*
Expand Down Expand Up @@ -1312,4 +1339,13 @@ export default {
margin-bottom: 16px;
}
}

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

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

0 comments on commit fb4c381

Please sign in to comment.