From 52c94d22ad15199b50c7759283624c666c7dd9b1 Mon Sep 17 00:00:00 2001 From: ae Date: Fri, 18 Apr 2025 20:28:24 +0300 Subject: [PATCH] feat: 100% width sidebar on mobile --- web/src/app.css | 30 ++++++++++++++++++- web/src/lib/components/NoteView.svelte | 41 +++++++++++++++++++------- web/src/lib/components/Sidebar.svelte | 36 ++++++++++++++++++---- 3 files changed, 91 insertions(+), 16 deletions(-) diff --git a/web/src/app.css b/web/src/app.css index 4e16200..7a56c83 100644 --- a/web/src/app.css +++ b/web/src/app.css @@ -168,8 +168,24 @@ } /* Sidebar */ + @media (max-width: 768px) { + .sidebar { + @apply w-full max-w-full; + } + + body.sidebar-open { + @apply overflow-hidden; + } + } + + @media (min-width: 768px) { + .sidebar { + @apply w-64; + } + } + .sidebar { - @apply fixed flex h-full w-64 flex-col overflow-hidden border-r border-[var(--light-foreground)] bg-[var(--light-foreground)] transition-all duration-300; + @apply fixed flex h-full flex-col overflow-hidden border-r border-[var(--light-foreground)] bg-[var(--light-foreground)] transition-all duration-300; } .dark .sidebar { @@ -453,6 +469,18 @@ } /* Main layout */ + .main-layout-container { + @apply flex h-screen bg-[var(--light-background)]; + } + + .dark .main-layout-container { + @apply bg-[var(--dark-background)]; + } + + .main-error-popup { + @apply fixed top-4 right-4 z-50 max-w-md; + } + .main-header { @apply flex items-center justify-between bg-[var(--light-foreground)] p-4 shadow-sm; } diff --git a/web/src/lib/components/NoteView.svelte b/web/src/lib/components/NoteView.svelte index 5583620..06b0730 100644 --- a/web/src/lib/components/NoteView.svelte +++ b/web/src/lib/components/NoteView.svelte @@ -19,11 +19,11 @@ export let isLoading = false // State - let sidebarOpen = true + let sidebarOpen = false let showSettings = false let isEditing = false - onMount(async () => { + onMount(async (): Promise => { isLoading = true try { @@ -44,6 +44,22 @@ } finally { isLoading = false } + + // Default to sidebar closed on mobile + const handleResize = () => { + if (window.innerWidth < 768 && sidebarOpen) { + sidebarOpen = false + } + } + + handleResize() + + // Keep listening to browser's resize events + window.addEventListener("resize", handleResize) + + return () => { + window.removeEventListener("resize", handleResize) + } }) const loadNotes = async () => { @@ -59,6 +75,10 @@ sidebarOpen = !sidebarOpen } + const closeSidebar = () => { + sidebarOpen = false + } + const toggleSettings = () => { showSettings = !showSettings } @@ -81,9 +101,9 @@ } } - // TODO: add caching (!!!) - const selectNote = async (noteId: string) => { + // TODO: check from cache props first before requesting from API + console.log(`loading ${noteId}`) const note = await apiClient.getFullNote(noteId) @@ -116,10 +136,10 @@ } -
+
{#if $cError} -
+
{$cError} @@ -127,22 +147,23 @@
{/if} - +
diff --git a/web/src/lib/components/Sidebar.svelte b/web/src/lib/components/Sidebar.svelte index 93ada1c..7e549ad 100644 --- a/web/src/lib/components/Sidebar.svelte +++ b/web/src/lib/components/Sidebar.svelte @@ -1,5 +1,6 @@