Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion interface/src/lib/components/UpdateIndicator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions interface/src/lib/components/toasts/notifications.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand All @@ -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) {
Expand All @@ -32,7 +32,7 @@ function createNotificationStore() {
clearTimeout(timer);
};
}
});
}) as Writable<State[]>;
const { subscribe } = notifications;

return {
Expand Down
8 changes: 1 addition & 7 deletions interface/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

export let data: LayoutData;

//$: console.log($analytics);

onMount(() => {
if ($user.bearer_token !== '') {
validateUser($user);
Expand All @@ -31,10 +29,6 @@
NotificationSource?.close();
});

onDestroy(() => {
NotificationSource.close();
});

async function validateUser(userdata: userProfile) {
try {
const response = await fetch('/rest/verifyAuthorization', {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion interface/src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 2 additions & 6 deletions interface/src/routes/menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -179,7 +175,7 @@
on:click={() => setActiveMenuItem(menuItems, '')}
>
<img src={logo} alt="Logo" class="h-12 w-12" />
<h1 class="px-4 text-2xl font-bold">{appName}</h1>
<h1 class="px-4 text-2xl font-bold">{$page.data.appName}</h1>
</a>
<ul class="menu rounded-box menu-vertical flex-nowrap overflow-y-auto">
{#each menuItems as menuItem, i (menuItem.title)}
Expand Down Expand Up @@ -260,7 +256,7 @@
>
{/if}
<div class="inline-flex flex-grow items-center justify-end text-sm">
<Copyright class="h-4 w-4" /><span class="px-2">{copyright}</span>
<Copyright class="h-4 w-4" /><span class="px-2">{$page.data.copyright}</span>
</div>
</div>
</div>