diff --git a/interface/src/lib/components/UpdateIndicator.svelte b/interface/src/lib/components/UpdateIndicator.svelte index 55ea3608..82bc041f 100644 --- a/interface/src/lib/components/UpdateIndicator.svelte +++ b/interface/src/lib/components/UpdateIndicator.svelte @@ -17,9 +17,10 @@ let firmwareDownloadLink: string; async function getGithubAPI() { + const githubUrl = `https://api.github.com/repos/${$page.data.github}/releases/latest`; try { const response = await fetch( - 'https://api.github.com/repos/' + $page.data.github + '/releases/latest', + githubUrl, { method: 'GET', headers: { @@ -28,6 +29,9 @@ } } ); + if (response.status !== 200) { + throw new Error(`Failed to fetch latest release from ${githubUrl}`); + } const results = await response.json(); update = false; diff --git a/interface/src/lib/components/toasts/notifications.ts b/interface/src/lib/components/toasts/notifications.ts index 9ac69647..1fcdbf06 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 { diff --git a/interface/src/routes/+layout.svelte b/interface/src/routes/+layout.svelte index ac78686f..066a9b09 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); @@ -31,10 +29,6 @@ NotificationSource?.close(); }); - onDestroy(() => { - NotificationSource.close(); - }); - async function validateUser(userdata: userProfile) { try { const response = await fetch('/rest/verifyAuthorization', { @@ -162,7 +156,7 @@ function reconnectEventSource() { if (connectionLost === false) { - NotificationSource.close; + NotificationSource.close(); notifications.error('Connection to device lost', 5000); if (reconnectIntervalId === 0) { reconnectIntervalId = setInterval(connectToEventSource, 2000); diff --git a/interface/src/routes/+layout.ts b/interface/src/routes/+layout.ts index a89ad664..4e1fd2ef 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 732cc6de..169ce948 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}