From 2d706b2b81dc64957f32518a8986a0428505eec0 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 27 Apr 2024 16:16:57 +0200 Subject: [PATCH] Add fullscreen mode for chat Signed-off-by: Emmy D'Anello --- chat/static/chat.js | 24 ++++++++++++++++++++++-- chat/templates/chat/chat.html | 8 +++++++- chat/views.py | 10 ++-------- locale/fr/LC_MESSAGES/django.po | 22 +++++++++++++--------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/chat/static/chat.js b/chat/static/chat.js index 9172c97..af028d2 100644 --- a/chat/static/chat.js +++ b/chat/static/chat.js @@ -33,6 +33,8 @@ function selectChannel(channel_id) { selected_channel_id = channel_id + window.history.replaceState({}, null, `#channel-${channel['id']}`) + let channelTitle = document.getElementById('channel-title') channelTitle.innerText = channel['name'] @@ -84,8 +86,12 @@ function setChannels(new_channels) { fetchMessages(channel['id']) } - if (new_channels && (!selected_channel_id || !channels[selected_channel_id])) - selectChannel(Object.keys(channels)[0]) + if (new_channels && (!selected_channel_id || !channels[selected_channel_id])) { + if (window.location.hash) + selectChannel(window.location.hash.substring(9)) + else + selectChannel(Object.keys(channels)[0]) + } } function receiveMessage(message) { @@ -180,6 +186,20 @@ function redrawMessages() { fetchMoreButton.classList.remove('d-none') } +function toggleFullscreen() { + let chatContainer = document.getElementById('chat-container') + 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}`) + } + 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}`) + } +} + document.addEventListener('DOMContentLoaded', () => { /** * Process the received data from the server. diff --git a/chat/templates/chat/chat.html b/chat/templates/chat/chat.html index 81e5c21..a57bb63 100644 --- a/chat/templates/chat/chat.html +++ b/chat/templates/chat/chat.html @@ -3,6 +3,8 @@ {% load static %} {% load i18n %} +{% block content-title %}{% endblock %} + {% block content %}