From 8f9f5c76cb81f8d5bf19c5dad76611d5f9f7c17c Mon Sep 17 00:00:00 2001 From: ae Date: Mon, 21 Apr 2025 22:21:30 +0300 Subject: [PATCH] feat: proper notification (error/success) handling --- web/src/app.css | 70 +++++++------ web/src/lib/components/AuthForm.svelte | 6 +- web/src/lib/components/NoteView.svelte | 110 +++++++++++++++----- web/src/lib/components/SettingsModal.svelte | 52 +++++---- web/src/lib/components/Sidebar.svelte | 2 +- web/src/lib/const.ts | 4 + web/src/lib/icons/Close.svelte | 8 +- web/src/routes/login/+page.svelte | 2 +- 8 files changed, 158 insertions(+), 96 deletions(-) diff --git a/web/src/app.css b/web/src/app.css index 0ac8d70..79b15ef 100644 --- a/web/src/app.css +++ b/web/src/app.css @@ -5,11 +5,19 @@ --light-foreground: #e0e0e0; --light-accent: #303052; --light-text: rgb(34, 40, 49); + --light-error-text: #4b0000; + --light-error-background: #fcaaaae1; + --light-success-text: #004b0a; + --light-success-background: #adfcaae1; --dark-background: #181818; --dark-foreground: #222222; --dark-accent: #bebff7; --dark-text: rgb(238, 238, 238); + --dark-error-text: #fcadaa; + --dark-error-background: #4b0000e0; + --dark-success-text: #adfcaa; + --dark-success-background: #004b0ae0; } /* Scrollbar width */ @@ -79,7 +87,7 @@ } button { - @apply rounded-md bg-[var(--light-accent)] px-4 py-2 text-[var(--light-background)] transition-all duration-200; + @apply cursor-pointer rounded-md bg-[var(--light-accent)] px-4 py-2 text-[var(--light-background)] transition-all duration-200; } button:hover { @@ -131,20 +139,20 @@ /* Error messages */ .error { - @apply rounded-lg bg-red-100 p-3 text-sm text-red-500; + @apply flex items-center justify-between rounded-lg bg-[var(--light-error-background)] p-3 text-sm text-[var(--light-error-text)]; } .dark .error { - @apply bg-red-900/30 text-red-300; + @apply bg-[var(--dark-error-background)] text-[var(--dark-error-text)]; } /* Success messages */ .success { - @apply rounded-lg bg-green-100 p-3 text-sm text-green-500; + @apply flex items-center justify-between rounded-lg bg-[var(--light-success-background)] p-3 text-sm text-[var(--light-success-text)]; } .dark .success { - @apply bg-green-900/30 text-green-300; + @apply bg-[var(--dark-success-background)] text-[var(--dark-success-text)]; } .btn-primary { @@ -185,13 +193,18 @@ } .sidebar { - @apply fixed flex h-full flex-col overflow-hidden border-r border-[var(--light-foreground)] bg-[var(--light-foreground)] transition-all duration-300; + @apply fixed z-10 flex h-full flex-col overflow-hidden border-r border-[var(--light-foreground)] bg-[var(--light-foreground)] transition-all duration-300; } .dark .sidebar { @apply border-[var(--dark-foreground)] bg-[var(--dark-foreground)]; } + .sidebar-header { + /* Should align with the navbar height for visual consistency */ + @apply h-20; + } + .sidebar-header, .sidebar-footer { @apply border-[var(--light-text)]/20 p-4; @@ -243,27 +256,11 @@ } .sidebar-item-delete { - @apply flex h-6.5 w-6.5 cursor-pointer items-center justify-center rounded-lg border-1 border-[var(--light-accent)]/20 bg-transparent p-1; + @apply flex h-6.5 w-6.5 items-center justify-center rounded-lg border-1 border-[var(--light-accent)]/20 bg-transparent p-1 text-[var(--light-accent)]/50 hover:text-[var(--light-accent)]; } .dark .sidebar-item-delete { - @apply border-[var(--dark-accent)]/20; - } - - .sidebar-item-delete > svg { - @apply text-[var(--light-accent)]/50; - } - - .dark .sidebar-item-delete > svg { - @apply text-[var(--dark-accent)]/50; - } - - .sidebar-item-delete:hover > svg { - @apply text-[var(--light-accent)] transition-colors delay-100; - } - - .dark .sidebar-item-delete:hover > svg { - @apply text-[var(--dark-accent)]; + @apply border-[var(--dark-accent)]/20 text-[var(--dark-accent)]/50 hover:text-[var(--dark-accent)]; } .sidebar-divider { @@ -304,7 +301,7 @@ } .versions-dropdown-item { - @apply w-full cursor-pointer bg-[var(--light-foreground)] p-3 transition-colors hover:bg-[var(--light-background)]; + @apply w-full bg-[var(--light-foreground)] p-3 transition-colors hover:bg-[var(--light-background)]; } .dark .versions-dropdown-item { @@ -521,15 +518,15 @@ /* Settings modal */ .modal-backdrop { - @apply fixed inset-0 z-50 flex items-center justify-center backdrop-blur-xs; + @apply fixed inset-0 z-40 flex items-center justify-center backdrop-blur-xs; } .modal-content { - @apply mx-4 max-h-[90vh] w-full max-w-md overflow-y-auto rounded-lg bg-[var(--light-background)] shadow-lg; + @apply mx-4 max-h-[90vh] w-full max-w-md overflow-y-auto rounded-lg border-2 border-[var(--light-accent)]/10 bg-[var(--light-background)] shadow-lg; } .dark .modal-content { - @apply bg-[var(--dark-background)]; + @apply border-[var(--dark-accent)]/10 bg-[var(--dark-background)]; } .modal-section { @@ -541,11 +538,11 @@ } .modal-close-button { - @apply text-[var(--light-background)]/60 hover:text-[var(--light-background)]; + @apply h-8 w-8 items-center justify-center rounded-md border-1 border-[var(--light-accent)]/20 bg-transparent p-1 text-[var(--light-accent)]/50 hover:text-[var(--light-accent)]; } .dark .modal-close-button { - @apply text-[var(--dark-background)]/60 hover:text-[var(--dark-background)]; + @apply border-[var(--dark-accent)]/20 text-[var(--dark-accent)]/50 hover:text-[var(--dark-accent)]; } /* Loading spinner */ @@ -615,12 +612,21 @@ } } - .main-error-popup { + .main-info-popup { + /* Z-value should be set so that this is on top of the modal's background blur */ @apply fixed top-4 right-4 z-50 max-w-md; } + .main-info-popup-button { + @apply ml-2 h-4 w-4 items-center justify-center rounded-md bg-transparent p-0 text-inherit; + } + .main-header { - @apply flex h-20 items-center justify-between bg-[var(--light-foreground)] p-4 shadow-sm; + /* + Should have higher z-value than the contents, but still less than the sidebar + (otherwise the navbar and the sidebar shadows will seem uneven). + */ + @apply z-5 flex h-20 items-center justify-between bg-[var(--light-foreground)] p-4 shadow-sm; } .dark .main-header { diff --git a/web/src/lib/components/AuthForm.svelte b/web/src/lib/components/AuthForm.svelte index 8a289af..6a4dd3c 100644 --- a/web/src/lib/components/AuthForm.svelte +++ b/web/src/lib/components/AuthForm.svelte @@ -41,11 +41,7 @@ return } - try { - await handler(username, password) - } catch (err) { - cError.set(err instanceof Error ? err.message : "Authentication failed") - } + await handler(username, password) } diff --git a/web/src/lib/components/NoteView.svelte b/web/src/lib/components/NoteView.svelte index 72a5753..937585f 100644 --- a/web/src/lib/components/NoteView.svelte +++ b/web/src/lib/components/NoteView.svelte @@ -1,5 +1,5 @@ {#if isComponentReady}
{#if $cError} -
+
{$cError} - + +
+
+ {/if} + + + {#if $cSuccess} +
+
+ {$cSuccess} +
{/if} diff --git a/web/src/lib/components/SettingsModal.svelte b/web/src/lib/components/SettingsModal.svelte index 61d623f..cfb0066 100644 --- a/web/src/lib/components/SettingsModal.svelte +++ b/web/src/lib/components/SettingsModal.svelte @@ -1,5 +1,5 @@