|
9 | 9 | import { SerializeWifiNetworkSaveCommand } from '$lib/Serializers/WifiNetworkSaveCommand'; |
10 | 10 | import WiFiDetailsDialog from '$lib/components/WiFiDetailsDialog.svelte'; |
11 | 11 | 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'; |
13 | 24 | import { ArrowRight, Link, LoaderCircle, RotateCcw, Wifi } from 'lucide-svelte'; |
14 | 25 |
|
15 | 26 | let scanStatus = $derived($HubStateStore.wifiScanStatus); |
|
27 | 38 | ) |
28 | 39 | ); |
29 | 40 |
|
| 41 | + let dialogOpen = $state(false); |
| 42 | + let pendingPassword = $state<string | null>(null); |
| 43 | +
|
30 | 44 | function wifiScan() { |
31 | 45 | const data = SerializeWifiScanCommand(!isScanning); |
32 | 46 | WebSocketClient.Instance.Send(data); |
33 | 47 | } |
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); |
52 | 52 | } |
53 | 53 | function wifiConnect(item: WiFiNetworkGroup) { |
54 | 54 | const data = SerializeWifiNetworkConnectCommand(item.ssid); |
|
58 | 58 | const data = SerializeWifiNetworkDisconnectCommand(); |
59 | 59 | WebSocketClient.Instance.Send(data); |
60 | 60 | } |
| 61 | +
|
| 62 | + function handleWifiAuthDialogOpenChange(open: boolean) { |
| 63 | + dialogOpen = open; |
| 64 | + if (!open) { |
| 65 | + pendingPassword = null; |
| 66 | + } |
| 67 | + } |
61 | 68 | </script> |
62 | 69 |
|
63 | 70 | <div> |
|
93 | 100 | <Button onclick={() => wifiConnect(netgroup)}> |
94 | 101 | <ArrowRight color="#22c55e" /> |
95 | 102 | </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" /> |
99 | 106 | </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> |
100 | 132 | {/if} |
101 | 133 | <WiFiDetailsDialog group={netgroup} /> |
102 | 134 | </div> |
|
0 commit comments