Skip to content

Commit 3127c04

Browse files
committed
Finish Svelte5 transition
1 parent dcbc63e commit 3127c04

File tree

3 files changed

+61
-26
lines changed

3 files changed

+61
-26
lines changed

frontend/src/lib/components/WiFiList.svelte

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
import { SerializeWifiNetworkSaveCommand } from '$lib/Serializers/WifiNetworkSaveCommand';
1010
import WiFiDetailsDialog from '$lib/components/WiFiDetailsDialog.svelte';
1111
import type { WiFiNetworkGroup } from '$lib/types';
12-
import { Button } from '$lib/components/ui/button';
12+
import { Button, buttonVariants } from '$lib/components/ui/button';
13+
import {
14+
Dialog,
15+
DialogContent,
16+
DialogDescription,
17+
DialogFooter,
18+
DialogHeader,
19+
DialogTitle,
20+
DialogTrigger,
21+
} from '$lib/components/ui/dialog';
22+
import { Input } from '$lib/components/ui/input';
23+
import { Label } from '$lib/components/ui/label';
1324
import { ArrowRight, Link, LoaderCircle, RotateCcw, Wifi } from 'lucide-svelte';
1425
1526
let scanStatus = $derived($HubStateStore.wifiScanStatus);
@@ -27,28 +38,17 @@
2738
)
2839
);
2940
41+
let dialogOpen = $state(false);
42+
let pendingPassword = $state<string | null>(null);
43+
3044
function wifiScan() {
3145
const data = SerializeWifiScanCommand(!isScanning);
3246
WebSocketClient.Instance.Send(data);
3347
}
34-
function wifiAuthenticate(item: WiFiNetworkGroup) {
35-
if (item.security !== WifiAuthMode.Open) {
36-
modalStore.trigger({
37-
type: 'prompt',
38-
title: 'Enter password',
39-
body: 'Enter the password for the network',
40-
value: '',
41-
valueAttr: { type: 'password', minlength: 1, maxlength: 63, required: true },
42-
response: (password: string) => {
43-
if (!password) return;
44-
const data = SerializeWifiNetworkSaveCommand(item.ssid, password, true);
45-
WebSocketClient.Instance.Send(data);
46-
},
47-
});
48-
} else {
49-
const data = SerializeWifiNetworkSaveCommand(item.ssid, null, true);
50-
WebSocketClient.Instance.Send(data);
51-
}
48+
function wifiAuthenticate(ssid: string, password: string | null) {
49+
dialogOpen = false;
50+
const data = SerializeWifiNetworkSaveCommand(ssid, null, true);
51+
WebSocketClient.Instance.Send(data);
5252
}
5353
function wifiConnect(item: WiFiNetworkGroup) {
5454
const data = SerializeWifiNetworkConnectCommand(item.ssid);
@@ -58,6 +58,13 @@
5858
const data = SerializeWifiNetworkDisconnectCommand();
5959
WebSocketClient.Instance.Send(data);
6060
}
61+
62+
function handleWifiAuthDialogOpenChange(open: boolean) {
63+
dialogOpen = open;
64+
if (!open) {
65+
pendingPassword = null;
66+
}
67+
}
6168
</script>
6269

6370
<div>
@@ -93,10 +100,35 @@
93100
<Button onclick={() => wifiConnect(netgroup)}>
94101
<ArrowRight color="#22c55e" />
95102
</Button>
96-
{:else}
97-
<Button onclick={() => wifiAuthenticate(netgroup)}>
98-
<Link color="#22c55e" />
103+
{:else if netgroup.security === WifiAuthMode.Open}
104+
<Button onclick={() => wifiAuthenticate(netgroup.ssid, null)}>
105+
<ArrowRight color="#22c55e" />
99106
</Button>
107+
{:else}
108+
<Dialog bind:open={() => dialogOpen, handleWifiAuthDialogOpenChange}>
109+
<DialogTrigger class={buttonVariants({ variant: 'outline' })}>
110+
<Link color="#22c55e" />
111+
</DialogTrigger>
112+
<DialogContent class="sm:max-w-[425px]">
113+
<DialogHeader>
114+
<DialogTitle>Enter password</DialogTitle>
115+
<DialogDescription>Enter the password for the network</DialogDescription>
116+
</DialogHeader>
117+
<div class="flex flex-row items-center gap-4 py-4">
118+
<Label for="name" class="text-right">Password</Label>
119+
<Input id="name" class="col-span-3" bind:value={pendingPassword} />
120+
</div>
121+
<DialogFooter>
122+
<Button
123+
type="button"
124+
onclick={() => wifiAuthenticate(netgroup.ssid, pendingPassword)}
125+
disabled={!pendingPassword || pendingPassword.length > 63}
126+
>
127+
Save changes
128+
</Button>
129+
</DialogFooter>
130+
</DialogContent>
131+
</Dialog>
100132
{/if}
101133
<WiFiDetailsDialog group={netgroup} />
102134
</div>
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { WifiAuthMode } from '$lib/_fbs/open-shock/serialization/types/wifi-auth-mode';
2-
import type { WiFiNetwork } from './WiFiNetwork';
32

43
export type WiFiNetworkGroup = {
54
ssid: string;
65
saved: boolean;
76
security: WifiAuthMode;
8-
networks: WiFiNetwork[];
7+
networks: {
8+
bssid: string;
9+
rssi: number;
10+
channel: number;
11+
}[];
912
};

frontend/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from 'vitest/config';
1+
import { defineConfig, type UserConfig } from 'vite';
22
import { sveltekit } from '@sveltejs/kit/vite';
33

44
export default defineConfig({
@@ -7,4 +7,4 @@ export default defineConfig({
77
test: {
88
include: ['src/**/*.{test,spec}.{js,ts}'],
99
},
10-
});
10+
} as UserConfig); // TODO: "test" is not a valid property of the defineconfig argument? This needs to get fixed

0 commit comments

Comments
 (0)