From db0e1eeb3b36788630cd2278b54fd815bf23b711 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 2 Apr 2024 18:49:25 +0200 Subject: [PATCH 1/6] Adds type for notification type --- interface/src/lib/components/toasts/notifications.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interface/src/lib/components/toasts/notifications.ts b/interface/src/lib/components/toasts/notifications.ts index 9ac696477..1fcdbf061 100644 --- a/interface/src/lib/components/toasts/notifications.ts +++ b/interface/src/lib/components/toasts/notifications.ts @@ -1,8 +1,10 @@ -import { writable, derived } from 'svelte/store'; +import { writable, derived, type Writable } from 'svelte/store'; + +type StateType = 'info' | 'success' | 'warning' | 'error'; type State = { id: string; - type: string; + type: StateType; message: string; timeout: number; }; @@ -11,14 +13,12 @@ function createNotificationStore() { const state: State[] = []; const _notifications = writable(state); - function send(message: string, type = 'info', timeout: number) { + function send(message: string, type: StateType = 'info', timeout: number) { _notifications.update((state) => { return [...state, { id: id(), type, message, timeout }]; }); } - let timers = []; - const notifications = derived(_notifications, ($_notifications, set) => { set($_notifications); if ($_notifications.length > 0) { @@ -32,7 +32,7 @@ function createNotificationStore() { clearTimeout(timer); }; } - }); + }) as Writable; const { subscribe } = notifications; return { From 6d7a3fc6f45a7f409ac833e11d6843f7a3d48788 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 2 Apr 2024 18:47:09 +0200 Subject: [PATCH 2/6] Removes duplicate code --- interface/src/routes/+layout.svelte | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface/src/routes/+layout.svelte b/interface/src/routes/+layout.svelte index ac78686f5..2d7f5bfe1 100644 --- a/interface/src/routes/+layout.svelte +++ b/interface/src/routes/+layout.svelte @@ -31,10 +31,6 @@ NotificationSource?.close(); }); - onDestroy(() => { - NotificationSource.close(); - }); - async function validateUser(userdata: userProfile) { try { const response = await fetch('/rest/verifyAuthorization', { From 744df749a946fd0f348da8953f66b1191d44caa9 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 2 Apr 2024 18:48:03 +0200 Subject: [PATCH 3/6] Closes notification channel --- interface/src/routes/+layout.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/routes/+layout.svelte b/interface/src/routes/+layout.svelte index 2d7f5bfe1..dc0c8e39b 100644 --- a/interface/src/routes/+layout.svelte +++ b/interface/src/routes/+layout.svelte @@ -158,7 +158,7 @@ function reconnectEventSource() { if (connectionLost === false) { - NotificationSource.close; + NotificationSource.close(); notifications.error('Connection to device lost', 5000); if (reconnectIntervalId === 0) { reconnectIntervalId = setInterval(connectToEventSource, 2000); From 5bdcdda53451853e136f1ceaac73761d423ad615 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 2 Apr 2024 18:48:17 +0200 Subject: [PATCH 4/6] Removes uncommented code --- interface/src/routes/+layout.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/routes/+layout.svelte b/interface/src/routes/+layout.svelte index dc0c8e39b..066a9b09b 100644 --- a/interface/src/routes/+layout.svelte +++ b/interface/src/routes/+layout.svelte @@ -17,8 +17,6 @@ export let data: LayoutData; - //$: console.log($analytics); - onMount(() => { if ($user.bearer_token !== '') { validateUser($user); From 2fc6d953bfd13b785fd5f59b0c713f975d40f587 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 2 Apr 2024 18:48:30 +0200 Subject: [PATCH 5/6] Moves appname and copyright to layoutts --- interface/src/routes/+layout.ts | 4 +++- interface/src/routes/menu.svelte | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/interface/src/routes/+layout.ts b/interface/src/routes/+layout.ts index a89ad6647..4e1fd2ef8 100644 --- a/interface/src/routes/+layout.ts +++ b/interface/src/routes/+layout.ts @@ -10,6 +10,8 @@ export const load = (async () => { return { features: item, title: 'ESP32-SvelteKit', - github: 'theelims/ESP32-sveltekit' + github: 'theelims/ESP32-sveltekit', + copyright: '2023 theelims', + appName: 'ESP32 SvelteKit' }; }) satisfies LayoutLoad; diff --git a/interface/src/routes/menu.svelte b/interface/src/routes/menu.svelte index 732cc6dea..169ce9489 100644 --- a/interface/src/routes/menu.svelte +++ b/interface/src/routes/menu.svelte @@ -22,10 +22,6 @@ import { user } from '$lib/stores/user'; import { createEventDispatcher } from 'svelte'; - const appName = 'ESP32 SvelteKit'; - - const copyright = '2023 theelims'; - const github = { href: 'https://github.com/' + $page.data.github, active: true }; const discord = { href: '.', active: false }; @@ -179,7 +175,7 @@ on:click={() => setActiveMenuItem(menuItems, '')} > Logo -

{appName}

+

{$page.data.appName}