🍎 Updates ui

This commit is contained in:
Rune Harlyk
2024-09-03 21:21:14 +02:00
committed by Rune Harlyk
parent 756f1c0148
commit 5e0b31aaf2
2 changed files with 864 additions and 820 deletions
+116 -113
View File
@@ -1,52 +1,52 @@
<script lang="ts"> <script lang="ts">
import { closeModal } from 'svelte-modals'; import { closeModal } from 'svelte-modals';
import { focusTrap } from 'svelte-focus-trap'; import { focusTrap } from 'svelte-focus-trap';
import { fly } from 'svelte/transition'; import { fly } from 'svelte/transition';
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import RssiIndicator from '$lib/components/statusbar/RSSIIndicator.svelte'; import RssiIndicator from '$lib/components/statusbar/RSSIIndicator.svelte';
import type { NetworkItem, NetworkList } from '$lib/types/models'; import type { NetworkItem, NetworkList } from '$lib/types/models';
import { api } from '$lib/api'; import { api } from '$lib/api';
import { AP, Network, Reload, Cancel } from '$lib/components/icons'; import { AP, Network, Reload, Cancel } from '$lib/components/icons';
// provided by <Modals /> // provided by <Modals />
export let isOpen: boolean; export let isOpen: boolean;
export let storeNetwork: any; export let storeNetwork: any;
const encryptionType = [ const encryptionType = [
'Open', 'Open',
'WEP', 'WEP',
'WPA PSK', 'WPA PSK',
'WPA2 PSK', 'WPA2 PSK',
'WPA WPA2 PSK', 'WPA WPA2 PSK',
'WPA2 Enterprise', 'WPA2 Enterprise',
'WPA3 PSK', 'WPA3 PSK',
'WPA2 WPA3 PSK', 'WPA2 WPA3 PSK',
'WAPI PSK' 'WAPI PSK'
]; ];
let listOfNetworks: NetworkItem[] = []; let listOfNetworks: NetworkItem[] = [];
let scanActive = false; let scanActive = false;
let pollingId: number; let pollingId: number;
async function scanNetworks() { async function scanNetworks() {
scanActive = true; scanActive = true;
if ((await pollingResults()) == false) {
pollingId = setInterval(() => pollingResults(), 1000);
}
return;
}
async function pollingResults() {
if (result.isErr()){
await api.get('/api/wifi/scan'); await api.get('/api/wifi/scan');
const result = await api.get<NetworkList>('/api/wifi/networks'); if ((await pollingResults()) == false) {
console.error(`Error occurred while fetching: `, result.inner); pollingId = setInterval(() => pollingResults(), 1000);
return false
} }
let response = result.inner return;
}
async function pollingResults() {
const result = await api.get<NetworkList>('/api/wifi/networks');
if (result.isErr()) {
console.error(`Error occurred while fetching: `, result.inner);
return false;
}
let response = result.inner;
listOfNetworks = response.networks; listOfNetworks = response.networks;
scanActive = false; scanActive = false;
if (listOfNetworks.length) { if (listOfNetworks.length) {
@@ -54,86 +54,89 @@
pollingId = 0; pollingId = 0;
} }
return listOfNetworks.length; return listOfNetworks.length;
} }
onMount(() => { onMount(() => {
scanNetworks(); scanNetworks();
}); });
onDestroy(() => { onDestroy(() => {
if (pollingId) { if (pollingId) {
clearInterval(pollingId); clearInterval(pollingId);
pollingId = 0; pollingId = 0;
} }
}); });
</script> </script>
{#if isOpen} {#if isOpen}
<div <div
role="dialog" role="dialog"
class="pointer-events-none fixed inset-0 z-50 flex items-center justify-center" class="pointer-events-none fixed inset-0 z-50 flex items-center justify-center"
transition:fly={{ y: 50 }} transition:fly={{ y: 50 }}
on:introstart on:introstart
on:outroend on:outroend
use:focusTrap use:focusTrap
> >
<div <div
class="bg-base-100 rounded-box pointer-events-auto flex max-h-full min-w-fit max-w-md flex-col justify-between p-4 shadow-lg" class="bg-base-100 rounded-box pointer-events-auto flex max-h-full min-w-fit max-w-md flex-col justify-between p-4 shadow-lg"
> >
<h2 class="text-base-content text-start text-2xl font-bold">Scan Networks</h2> <h2 class="text-base-content text-start text-2xl font-bold">Scan Networks</h2>
<div class="divider my-2" /> <div class="divider my-2" />
<div class="overflow-y-auto"> <div class="overflow-y-auto">
{#if scanActive}<div class="bg-base-100 flex flex-col items-center justify-center p-6"> {#if scanActive}<div
<AP class="text-secondary h-32 w-32 shrink animate-ping stroke-2" /> class="bg-base-100 flex flex-col items-center justify-center p-6"
<p class="mt-8 text-2xl">Scanning ...</p> >
</div> <AP class="text-secondary h-32 w-32 shrink animate-ping stroke-2" />
{:else} <p class="mt-8 text-2xl">Scanning ...</p>
<ul class="menu"> </div>
{#each listOfNetworks as network, i} {:else}
<li> <ul class="menu">
<!-- svelte-ignore a11y-click-events-have-key-events --> {#each listOfNetworks as network, i}
<div <li>
class="bg-base-200 rounded-btn my-1 flex items-center space-x-3 hover:scale-[1.02] active:scale-[0.98]" <!-- svelte-ignore a11y-click-events-have-key-events -->
on:click={() => { <div
storeNetwork(network.ssid); class="bg-base-200 rounded-btn my-1 flex items-center space-x-3 hover:scale-[1.02] active:scale-[0.98]"
}} on:click={() => {
storeNetwork(network.ssid);
}}
role="button" role="button"
tabindex="0" tabindex="0"
> >
<div class="mask mask-hexagon bg-primary h-auto w-10 shrink-0"> <div class="mask mask-hexagon bg-primary h-auto w-10 shrink-0">
<Network class="text-primary-content h-auto w-full scale-75" /> <Network
</div> class="text-primary-content h-auto w-full scale-75"
<div> />
<div class="font-bold">{network.ssid}</div> </div>
<div class="text-sm opacity-75"> <div>
Security: {encryptionType[network.encryption_type]}, Channel: {network.channel} <div class="font-bold">{network.ssid}</div>
</div> <div class="text-sm opacity-75">
</div> Security: {encryptionType[network.encryption_type]},
<div class="flex-grow" /> Channel: {network.channel}
<RssiIndicator </div>
showDBm={true} </div>
rssi={network.rssi} <div class="flex-grow" />
/> <RssiIndicator showDBm={true} rssi={network.rssi} />
</div> </div>
</li> </li>
{/each} {/each}
</ul> </ul>
{/if} {/if}
</div> </div>
<div class="divider my-2" /> <div class="divider my-2" />
<div class="flex flex-wrap justify-end gap-2"> <div class="flex flex-wrap justify-end gap-2">
<button <button
class="btn btn-primary inline-flex flex-none items-center" class="btn btn-primary inline-flex flex-none items-center"
disabled={scanActive} disabled={scanActive}
on:click={scanNetworks}><Reload class="mr-2 h-5 w-5" /><span>Scan again</span></button on:click={scanNetworks}
> ><Reload class="mr-2 h-5 w-5" /><span>Scan again</span></button
>
<div class="flex-grow" /> <div class="flex-grow" />
<button <button
class="btn btn-warning text-warning-content inline-flex flex-none items-center" class="btn btn-warning text-warning-content inline-flex flex-none items-center"
on:click={closeModal}><Cancel class="mr-2 h-5 w-5" /><span>Cancel</span></button on:click={closeModal}><Cancel class="mr-2 h-5 w-5" /><span>Cancel</span></button
> >
</div> </div>
</div> </div>
</div> </div>
{/if} {/if}
File diff suppressed because it is too large Load Diff