mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-22 03:18:24 +02:00
Add sort by unread messages option
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -95,7 +95,7 @@ async function addChannel(channel, categoryLists) {
|
||||
categoryList.parentElement.classList.remove('d-none')
|
||||
|
||||
let navItem = document.createElement('li')
|
||||
navItem.classList.add('list-group-item')
|
||||
navItem.classList.add('list-group-item', 'tab-channel')
|
||||
navItem.id = `tab-channel-${channel['id']}`
|
||||
navItem.setAttribute('data-bs-dismiss', 'offcanvas')
|
||||
navItem.onclick = () => selectChannel(channel['id'])
|
||||
@ -115,6 +115,9 @@ async function addChannel(channel, categoryLists) {
|
||||
unreadBadge.classList.add('d-none')
|
||||
channelButton.appendChild(unreadBadge)
|
||||
|
||||
if (document.getElementById('sort-by-unread-switch').checked)
|
||||
navItem.style.order = `${-channel.unread_messages}`
|
||||
|
||||
fetchMessages(channel['id'])
|
||||
}
|
||||
|
||||
@ -187,7 +190,8 @@ function markMessageAsRead(data) {
|
||||
}
|
||||
|
||||
function updateUnreadBadges(unreadMessages) {
|
||||
console.log(unreadMessages)
|
||||
const sortByUnread = document.getElementById('sort-by-unread-switch').checked
|
||||
|
||||
for (let channel of Object.values(channels)) {
|
||||
let unreadMessagesChannel = unreadMessages[channel['id']] || 0
|
||||
console.log(channel, unreadMessagesChannel)
|
||||
@ -199,6 +203,9 @@ function updateUnreadBadges(unreadMessages) {
|
||||
unreadBadge.classList.remove('d-none')
|
||||
else
|
||||
unreadBadge.classList.add('d-none')
|
||||
|
||||
if (sortByUnread)
|
||||
document.getElementById(`tab-channel-${channel['id']}`).style.order = `${-unreadMessagesChannel}`
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,6 +399,24 @@ function toggleFullscreen() {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.addEventListener('click', removeAllPopovers)
|
||||
|
||||
document.getElementById('sort-by-unread-switch').addEventListener('change', event => {
|
||||
const sortByUnread = event.target.checked
|
||||
for (let channel of Object.values(channels)) {
|
||||
let item = document.getElementById(`tab-channel-${channel['id']}`)
|
||||
if (sortByUnread)
|
||||
item.style.order = `${-channel.unread_messages}`
|
||||
else
|
||||
item.style.removeProperty('order')
|
||||
}
|
||||
|
||||
localStorage.setItem('chat.sort-by-unread', sortByUnread)
|
||||
})
|
||||
|
||||
if (localStorage.getItem('chat.sort-by-unread') === 'true') {
|
||||
document.getElementById('sort-by-unread-switch').checked = true
|
||||
document.getElementById('sort-by-unread-switch').dispatchEvent(new Event('change'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the received data from the server.
|
||||
* @param data The received message
|
||||
|
@ -9,6 +9,10 @@
|
||||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="offcanvas-body">
|
||||
<div class="form-switch form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="sort-by-unread-switch">
|
||||
<label class="form-check-label" for="sort-by-unread-switch">{% trans "Sort by unread messages" %}</label>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush" id="nav-channels-tab">
|
||||
<li class="list-group-item d-none">
|
||||
<h4>{% trans "General channels" %}</h4>
|
||||
|
Reference in New Issue
Block a user