1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-24 03:02:23 +00:00

Store last visited channel in local storage

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-04-28 23:56:41 +02:00
parent 80456f4da8
commit a41c17576f
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -33,8 +33,7 @@ function selectChannel(channel_id) {
}
selected_channel_id = channel_id
window.history.replaceState({}, null, `#channel-${channel['id']}`)
localStorage.setItem('chat.last-channel-id', channel_id)
let channelTitle = document.getElementById('channel-title')
channelTitle.innerText = channel['name']
@ -74,13 +73,9 @@ function setChannels(new_channels) {
addChannel(channel, categoryLists)
if (new_channels && (!selected_channel_id || !channels[selected_channel_id])) {
if (window.location.hash) {
let channel_id = parseInt(window.location.hash.substring(9))
if (channels[channel_id])
selectChannel(channel_id)
else
selectChannel(Object.keys(channels)[0])
}
let last_channel_id = parseInt(localStorage.getItem('chat.last-channel-id'))
if (last_channel_id && channels[last_channel_id])
selectChannel(last_channel_id)
else
selectChannel(Object.keys(channels)[0])
}
@ -387,12 +382,12 @@ function toggleFullscreen() {
if (!chatContainer.getAttribute('data-fullscreen')) {
chatContainer.setAttribute('data-fullscreen', 'true')
chatContainer.classList.add('position-absolute', 'top-0', 'start-0', 'vh-100', 'z-3')
window.history.replaceState({}, null, `?fullscreen=1#channel-${selected_channel_id}`)
window.history.replaceState({}, null, `?fullscreen=1`)
}
else {
chatContainer.removeAttribute('data-fullscreen')
chatContainer.classList.remove('position-absolute', 'top-0', 'start-0', 'vh-100', 'z-3')
window.history.replaceState({}, null, `?fullscreen=0#channel-${selected_channel_id}`)
window.history.replaceState({}, null, `?fullscreen=0`)
}
}