From daed66f7c62a184e93e975ca92850df4eb9372e3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 16 Apr 2024 15:57:14 -0500 Subject: [PATCH] feat: sidebar swipe support --- src/lib/components/layout/Sidebar.svelte | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 9537eed9..33334b38 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -45,6 +45,31 @@ show = true; } await chats.set(await getChatList(localStorage.token)); + + let touchstartX = 0; + let touchendX = 0; + + function checkDirection() { + const screenWidth = window.innerWidth; + const swipeDistance = Math.abs(touchendX - touchstartX); + if (swipeDistance >= screenWidth / 4) { + if (touchendX < touchstartX) { + show = false; + } + if (touchendX > touchstartX) { + show = true; + } + } + } + + document.addEventListener('touchstart', (e) => { + touchstartX = e.changedTouches[0].screenX; + }); + + document.addEventListener('touchend', (e) => { + touchendX = e.changedTouches[0].screenX; + checkDirection(); + }); }); // Helper function to fetch and add chat content to each chat @@ -706,6 +731,7 @@