From 8f5c671e4c4f3874d6ee4d73155134b62374b9e2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 15 May 2024 08:13:14 -1000 Subject: [PATCH] refac: sidebar breakpoint --- .../chat/Messages/UserMessage.svelte | 2 +- src/lib/components/layout/Sidebar.svelte | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index 5b9638ad5..689008e22 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -60,7 +60,7 @@ class="prose chat-{message.role} w-full max-w-full flex flex-col justify-end dark:prose-invert prose-headings:my-0 prose-p:my-0 prose-p:-mb-4 prose-pre:my-0 prose-table:my-0 prose-blockquote:my-0 prose-img:my-0 prose-ul:-my-4 prose-ol:-my-4 prose-li:-my-3 prose-ul:-mb-6 prose-ol:-mb-6 prose-li:-mb-4 whitespace-pre-line" > {#if message.files} -
+
{#each message.files as file}
{#if file.type === 'image'} diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index c4f4d2543..576929ed0 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -76,7 +76,26 @@ } }); + mobile; + const onResize = () => { + if ($showSidebar && window.innerWidth < BREAKPOINT) { + showSidebar.set(false); + } + }; + onMount(async () => { + mobile.subscribe((e) => { + console.log(e); + + if ($showSidebar && e) { + showSidebar.set(false); + } + + if (!$showSidebar && !e) { + showSidebar.set(true); + } + }); + showSidebar.set(window.innerWidth > BREAKPOINT); await chats.set(await getChatList(localStorage.token)); @@ -106,20 +125,12 @@ checkDirection(); }; - const onResize = () => { - if ($showSidebar && window.innerWidth < BREAKPOINT) { - showSidebar.set(false); - } - }; - window.addEventListener('touchstart', onTouchStart); window.addEventListener('touchend', onTouchEnd); - window.addEventListener('resize', onResize); return () => { window.removeEventListener('touchstart', onTouchStart); window.removeEventListener('touchend', onTouchEnd); - window.removeEventListener('resize', onResize); }; }); @@ -207,7 +218,7 @@ bind:this={navElement} id="sidebar" class="h-screen max-h-[100dvh] min-h-screen select-none {$showSidebar - ? 'lg:relative w-[260px]' + ? 'md:relative w-[260px]' : '-translate-x-[260px] w-[0px]'} bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-200 text-sm transition fixed z-50 top-0 left-0 rounded-r-2xl " data-state={$showSidebar}