Skip to content

Commit 49f50f1

Browse files
committed
Some cleanup
1 parent 3a9afc6 commit 49f50f1

11 files changed

Lines changed: 91 additions & 63 deletions

File tree

src/app.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ declare global {
1414
turnstile: TurnstileInstance | undefined;
1515
}
1616
interface ObjectConstructor {
17-
hasOwn<T extends object, K extends PropertyKey>(
18-
o: T,
19-
prop: K,
20-
): o is T & Record<K, unknown>;
17+
hasOwn<T extends object, K extends PropertyKey>(o: T, prop: K): o is T & Record<K, unknown>;
2118
}
2219
}
2320

src/lib/api/index.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
APITokensApi,
44
AccountApi as AccountV1Api,
55
AdminApi,
6+
type ConfigurationParameters,
67
Configuration as ConfigurationV1,
78
HubManagementApi as HubManagementV1Api,
89
MetaApi,
@@ -20,11 +21,6 @@ import {
2021
ShockersApi as ShockersV2Api,
2122
} from './internal/v2';
2223

23-
type Config = {
24-
basePath?: string;
25-
credentials?: RequestCredentials;
26-
};
27-
2824
function GetBasePath() {
2925
const domain = (PUBLIC_BACKEND_API_DOMAIN || undefined) as string | undefined;
3026

@@ -39,23 +35,15 @@ function GetBasePath() {
3935
return 'https://' + domain; // TODO: Add configurable protocol
4036
}
4137

42-
function GetConfig(): Config {
38+
function GetConfig(): ConfigurationParameters {
4339
return {
4440
basePath: GetBasePath(),
4541
credentials: 'include',
4642
};
4743
}
4844

49-
export function GetV1Config() {
50-
return new ConfigurationV1(GetConfig());
51-
}
52-
53-
export function GetV2Config() {
54-
return new ConfigurationV2(GetConfig());
55-
}
56-
57-
const DefaultApiV1Configuration = GetV1Config();
58-
const DefaultApiV2Configuration = GetV2Config();
45+
const DefaultApiV1Configuration = new ConfigurationV1(GetConfig());
46+
const DefaultApiV2Configuration = new ConfigurationV2(GetConfig());
5947

6048
export const accountV1Api = new AccountV1Api(DefaultApiV1Configuration);
6149
export const accountV2Api = new AccountV2Api(DefaultApiV2Configuration);

src/lib/components/AbsolutelySureButton.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import type { IntervalHandle, TimeoutHandle } from '$lib/types/WAPI';
3+
import { cn } from '$lib/utils';
34
import { onDestroy } from 'svelte';
45
56
interface Props {
@@ -52,7 +53,10 @@
5253
onpointerdown={startConfirm}
5354
onpointerup={stopTimers}
5455
onpointerleave={stopTimers}
55-
class={`h-10 rounded-md bg-[#7f1d1d] px-4 py-2 text-sm font-medium whitespace-nowrap select-none hover:bg-[#731a1a] focus:outline-hidden ${timer ? 'violent-shake' : ''}`}
56+
class={cn(
57+
'h-10 rounded-md bg-[#7f1d1d] px-4 py-2 text-sm font-medium whitespace-nowrap select-none hover:bg-[#731a1a] focus:outline-hidden',
58+
{ 'violent-shake': timer !== null }
59+
)}
5660
>
5761
{buttonText}
5862
</button>

src/lib/components/LightSwitch.svelte

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
getDarkReaderState,
1010
willActivateLightMode,
1111
} from '$lib/stores/ColorSchemeStore';
12+
import { cn } from '$lib/utils';
1213
import { toast } from 'svelte-sonner';
1314
1415
let pendingScheme = $state<'light' | 'dark' | 'system' | undefined>();
@@ -51,7 +52,7 @@
5152

5253
<DropdownMenu.Root>
5354
<DropdownMenu.Trigger
54-
class={buttonVariants({ variant: 'ghost' }) + ' size-8! text-gray-600 dark:text-gray-300'}
55+
class={cn(buttonVariants({ variant: 'ghost' }), 'size-8! text-gray-600 dark:text-gray-300')}
5556
>
5657
<Sun class="size-[1.2rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" />
5758
<Moon
@@ -60,8 +61,14 @@
6061
<span class="sr-only">Toggle theme</span>
6162
</DropdownMenu.Trigger>
6263
<DropdownMenu.Content align="end">
63-
<DropdownMenu.Item onclick={() => evaluateLightSwitch('light')}>Light</DropdownMenu.Item>
64-
<DropdownMenu.Item onclick={() => evaluateLightSwitch('dark')}>Dark</DropdownMenu.Item>
65-
<DropdownMenu.Item onclick={() => evaluateLightSwitch('system')}>System</DropdownMenu.Item>
64+
<DropdownMenu.Item class="cursor-pointer" onclick={() => evaluateLightSwitch('light')}
65+
>Light</DropdownMenu.Item
66+
>
67+
<DropdownMenu.Item class="cursor-pointer" onclick={() => evaluateLightSwitch('dark')}
68+
>Dark</DropdownMenu.Item
69+
>
70+
<DropdownMenu.Item class="cursor-pointer" onclick={() => evaluateLightSwitch('system')}
71+
>System</DropdownMenu.Item
72+
>
6673
</DropdownMenu.Content>
6774
</DropdownMenu.Root>

src/lib/components/layout/Header.svelte

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
<script lang="ts">
22
import PanelLeft from '@lucide/svelte/icons/panel-left';
3+
import { goto } from '$app/navigation';
34
import { PUBLIC_DISCORD_INVITE_URL, PUBLIC_GITHUB_PROJECT_URL } from '$env/static/public';
45
import LightSwitch from '$lib/components/LightSwitch.svelte';
6+
import DiscordIcon from '$lib/components/svg/DiscordIcon.svelte';
7+
import GithubIcon from '$lib/components/svg/GithubIcon.svelte';
58
import * as Breadcrumb from '$lib/components/ui/breadcrumb';
69
import { Button } from '$lib/components/ui/button';
710
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
811
import { useSidebar } from '$lib/components/ui/sidebar';
912
import { BreadCrumbStore } from '$lib/stores/BreadCrumbStore';
1013
import { UserStore } from '$lib/stores/UserStore';
14+
import { cn } from '$lib/utils';
1115
1216
let sidebar = useSidebar();
1317
</script>
1418

15-
{#snippet item(text: string, href: string)}
19+
{#snippet dropdownItem(name: string, url: string)}
20+
<DropdownMenu.Item class="cursor-pointer" onclick={() => goto(url)}>
21+
{name}
22+
</DropdownMenu.Item>
23+
{/snippet}
24+
{#snippet headerItem(text: string, href: string)}
1625
<Button {href}>{text}</Button>
1726
{/snippet}
1827

1928
<header
2029
class="border-border/40 bg-background/95 supports-backdrop-filter:bg-background/60 sticky top-0 z-50 flex h-12 w-full flex-row items-center border-b px-2 backdrop-blur-sm"
2130
>
22-
<Button
23-
variant="ghost"
24-
class="size-8"
25-
onclick={() => {
26-
sidebar.toggle();
27-
}}
28-
>
31+
<Button variant="ghost" class="size-8" onclick={() => sidebar.toggle()}>
2932
<PanelLeft size={24} class="m-0 text-gray-600 dark:text-gray-300" />
3033
</Button>
3134
{#if $BreadCrumbStore.length > 0}
@@ -49,7 +52,10 @@
4952
</Breadcrumb.Root>
5053
{/if}
5154
<div
52-
class={`flex flex-1 flex-row items-center justify-between space-x-2 py-2 ${$UserStore.self ? 'pr-2' : 'px-2'}`}
55+
class={cn(
56+
'flex flex-1 flex-row items-center justify-between space-x-2 py-2',
57+
$UserStore.self !== null ? 'pr-2' : 'px-2'
58+
)}
5359
>
5460
<div class="flex-1"></div>
5561

@@ -69,37 +75,21 @@
6975
</DropdownMenu.Trigger>
7076
<DropdownMenu.Content>
7177
<DropdownMenu.Group>
72-
<DropdownMenu.Item>Profile</DropdownMenu.Item>
73-
<DropdownMenu.Item>Settings</DropdownMenu.Item>
74-
<DropdownMenu.Item>Logout</DropdownMenu.Item>
78+
{@render dropdownItem('Profile', '/profile')}
79+
{@render dropdownItem('Settings', '/settings/account')}
80+
{@render dropdownItem('Logout', '/logout')}
7581
</DropdownMenu.Group>
7682
</DropdownMenu.Content>
7783
</DropdownMenu.Root>
7884
{:else}
79-
{@render item('Login', '/login')}
80-
{@render item('Sign Up', '/signup')}
85+
{@render headerItem('Login', '/login')}
86+
{@render headerItem('Sign Up', '/signup')}
8187
<div class="hidden sm:flex sm:flex-row">
8288
<a href={PUBLIC_GITHUB_PROJECT_URL} class="p-2" aria-label="GitHub">
83-
<svg
84-
role="img"
85-
viewBox="0 0 24 24"
86-
xmlns="http://www.w3.org/2000/svg"
87-
class="size-6 fill-black dark:fill-white"
88-
><title>GitHub</title><path
89-
d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"
90-
/></svg
91-
>
89+
<GithubIcon class="size-6 fill-black dark:fill-white" />
9290
</a>
9391
<a href={PUBLIC_DISCORD_INVITE_URL} class="p-2" aria-label="Discord">
94-
<svg
95-
role="img"
96-
viewBox="0 0 24 24"
97-
xmlns="http://www.w3.org/2000/svg"
98-
class="size-6 fill-black dark:fill-white"
99-
><title>Discord</title><path
100-
d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z"
101-
/></svg
102-
>
92+
<DiscordIcon class="size-6 fill-black dark:fill-white" />
10393
</a>
10494
</div>
10595
{/if}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
interface Props {
3+
class?: string;
4+
}
5+
6+
let props: Props = $props();
7+
</script>
8+
9+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class={props.class}>
10+
<title>Discord</title>
11+
<path
12+
d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z"
13+
/>
14+
</svg>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
interface Props {
3+
class?: string;
4+
}
5+
6+
let props: Props = $props();
7+
</script>
8+
9+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class={props.class}>
10+
<title>GitHub</title>
11+
<path
12+
d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"
13+
/>
14+
</svg>

src/lib/constants/WebApiSupport.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
import { browser } from "$app/environment";
1+
import { browser } from '$app/environment';
22

3-
export const isSerialSupported = browser && ('serial' in navigator) && typeof navigator.serial.getPorts === 'function' && typeof navigator.serial.requestPort === 'function' && typeof navigator.serial.addEventListener === 'function';
3+
export const isSerialSupported =
4+
browser &&
5+
'serial' in navigator &&
6+
typeof navigator.serial.getPorts === 'function' &&
7+
typeof navigator.serial.requestPort === 'function' &&
8+
typeof navigator.serial.addEventListener === 'function';

src/lib/stores/FlashManagersStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { isSerialSupported } from '$lib/constants/WebApiSupport';
21
import FlashManager from '$lib/EspTool/FlashManager';
2+
import { isSerialSupported } from '$lib/constants/WebApiSupport';
33
import type { IEspLoaderTerminal } from 'esptool-js';
44
import { get, writable } from 'svelte/store';
55

src/routes/(authenticated)/hubs/[hubId=guid]/update/+page.svelte

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import { DownloadCloud, RotateCcw } from '@lucide/svelte';
33
import { page } from '$app/state';
44
import { hubManagementV1Api } from '$lib/api';
5-
import type { OtaItem, OtaItemIReadOnlyCollectionLegacyDataResponse } from '$lib/api/internal/v1';
5+
import {
6+
type OtaItem,
7+
type OtaItemIReadOnlyCollectionLegacyDataResponse,
8+
OtaUpdateStatus,
9+
} from '$lib/api/internal/v1';
610
import Container from '$lib/components/Container.svelte';
711
import FirmwareChannelSelector from '$lib/components/FirmwareChannelSelector.svelte';
812
import Button from '$lib/components/ui/button/button.svelte';
@@ -12,6 +16,7 @@
1216
import { handleApiError } from '$lib/errorhandling/apiErrorHandling';
1317
import { SignalR_Connection } from '$lib/signalr';
1418
import { type HubOnlineState, OnlineHubsStore } from '$lib/stores/HubsStore';
19+
import { cn } from '$lib/utils';
1520
import { NumberToHexPadded } from '$lib/utils/convert';
1621
1722
let hubId = $derived(page.params.hubId);
@@ -100,7 +105,11 @@
100105
{NumberToHexPadded(otaLog.id, 8)}
101106
</Table.Cell>
102107
<Table.Cell class="font-medium">{otaLog.startedAt.toDateString()}</Table.Cell>
103-
<Table.Cell class={`font-medium${otaLog.status == 'Finished' ? '' : ' text-red-500'}`}>
108+
<Table.Cell
109+
class={cn('font-medium', {
110+
'text-red-500': otaLog.status !== OtaUpdateStatus.Finished,
111+
})}
112+
>
104113
{otaLog.status}
105114
</Table.Cell>
106115
<Table.Cell class="font-medium">{otaLog.version}</Table.Cell>

0 commit comments

Comments
 (0)