Skip to content

Commit

Permalink
fixup! Fix(MessagesList): make the datetimestamp the id to each section
Browse files Browse the repository at this point in the history
  • Loading branch information
DorraJaouad committed Feb 23, 2024
1 parent 45da014 commit 56027f4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ get the messagesList array and loop through the list to generate the messages.
:class="{'has-sticky': dateTimestamp === stickyDate}">
<li class="messages-group__date">
<span class="messages-group__date-text" role="heading" aria-level="3">
{{ generateDateSeparator(dateTimestamp) }}
{{ dateSeparatorLabels[dateTimestamp] }}
</span>
</li>
<component :is="messagesGroupComponent(group)"
Expand Down Expand Up @@ -182,6 +182,8 @@ export default {
isScrolling: false,

stickyDate: null,

dateSeparatorLabels: {},
}
},

Expand Down Expand Up @@ -256,6 +258,10 @@ export default {
chatIdentifier() {
return this.token + ':' + this.isParticipant + ':' + this.viewId
},

currentDay() {
return moment().startOf('day').unix()
},
},

watch: {
Expand Down Expand Up @@ -300,6 +306,13 @@ export default {
}
},
},

currentDay() {
this.dateSeparatorLabels = {}
Object.keys(this.messagesGroupedByDateByAuthor).forEach(dateTimestamp => {
this.dateSeparatorLabels[dateTimestamp] = this.generateDateSeparator(dateTimestamp)
})
},
},

mounted() {
Expand Down Expand Up @@ -366,6 +379,11 @@ export default {
} else {
dateTimestamp = moment(message.timestamp * 1000).startOf('day').unix()
}

if (!this.dateSeparatorLabels[dateTimestamp]) {
this.dateSeparatorLabels[dateTimestamp] = this.generateDateSeparator(dateTimestamp)
}

if (!groupsByDate[dateTimestamp]) {
groupsByDate[dateTimestamp] = {}
}
Expand Down Expand Up @@ -549,6 +567,8 @@ export default {
* @return {string} Translated string of "<Today>, <November 11th, 2019>", "<3 days ago>, <November 8th, 2019>"
*/
generateDateSeparator(dateTimestamp) {
console.log('date generated', dateTimestamp)
console.trace()
const date = moment.unix(dateTimestamp).startOf('day')
// <Today>, <November 11th, 2019>
return t('spreed', '{relativeDate}, {absoluteDate}', {
Expand Down

0 comments on commit 56027f4

Please sign in to comment.