From 0c79ac0479263e95bf0f0899dffb78c84d29b3c4 Mon Sep 17 00:00:00 2001 From: insoutt Date: Sat, 27 Apr 2024 10:16:39 -0500 Subject: [PATCH] Hide sidevar when screen is resized to less than 1024 pixels --- src/lib/components/layout/Sidebar.svelte | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index aadf542ea..05d994da6 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -29,6 +29,7 @@ import ArchiveBox from '../icons/ArchiveBox.svelte'; import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte'; + const BREAKPOINT = 1024; let show = false; let navElement; @@ -49,9 +50,7 @@ let isEditing = false; onMount(async () => { - if (window.innerWidth > 1024) { - show = true; - } + show = window.innerWidth > BREAKPOINT; await chats.set(await getChatList(localStorage.token)); let touchstartX = 0; @@ -79,12 +78,20 @@ checkDirection(); }; + const onResize = () => { + if(show && window.innerWidth < BREAKPOINT) { + show = false; + } + } + document.addEventListener('touchstart', onTouchStart); document.addEventListener('touchend', onTouchEnd); + window.addEventListener('resize', onResize); return () => { document.removeEventListener('touchstart', onTouchStart); document.removeEventListener('touchend', onTouchEnd); + document.removeEventListener('resize', onResize); }; }); @@ -473,14 +480,14 @@
{#if chatTitleEditId === chat.id}