Skip to content

Commit 15c4dd9

Browse files
authored
Add route removal functionality and fix code formatting (#206)
- Add removeRouteAction function to allow disabling active routes - Update approveDeviceRoute to accept full routes array instead of single route
1 parent 7dd92ab commit 15c4dd9

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/lib/devices/DeviceCard/DeviceRoutes/DeviceRoute.svelte

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script>
22
import { getDevices } from '$lib/common/apiFunctions.svelte';
3-
import { Device } from '$lib/common/classes';
3+
import { Device } from '$lib/common/classes';
44
import { alertStore } from '$lib/common/stores';
55
import { approveDeviceRoute } from './DeviceRouteAPI.svelte';
66
7-
export let route = ""
8-
export let device = new Device();
7+
export let route = '';
8+
export let device = new Device();
99
1010
let routeDisabled = false;
1111
function approveRouteAction() {
12-
approveDeviceRoute(device.id, [route])
12+
approveDeviceRoute(device.id, [...device.approvedRoutes, route])
1313
.then(() => {
1414
// refresh users after editing
1515
getDevices();
@@ -19,11 +19,29 @@
1919
});
2020
}
2121
22+
function removeRouteAction() {
23+
approveDeviceRoute(device.id, device.approvedRoutes.filter((r) => r !== route))
24+
.then(() => {
25+
// refresh users after editing
26+
getDevices();
27+
})
28+
.catch((error) => {
29+
$alertStore = error;
30+
});
31+
}
2232
</script>
2333

2434
{route}
2535
{#if device.approvedRoutes.includes(route)}
26-
<button type="button" class="btn btn-xs tooltip capitalize bg-success text-success-content mx-1">active</button>
36+
<button
37+
on:click={() => {
38+
routeDisabled = true;
39+
removeRouteAction();
40+
routeDisabled = false;
41+
}}
42+
type="button"
43+
class="btn btn-xs tooltip capitalize bg-success text-success-content mx-1">active</button
44+
>
2745
{:else}
2846
<button
2947
on:click={() => {
@@ -32,7 +50,8 @@
3250
routeDisabled = false;
3351
}}
3452
type="button"
35-
class="btn btn-xs tooltip capitalize bg-secondary text-secondary-content mx-1" class:disabled={routeDisabled}
53+
class="btn btn-xs tooltip capitalize bg-secondary text-secondary-content mx-1"
54+
class:disabled={routeDisabled}
3655
data-tip="click to enable route">pending</button
3756
>
3857
{/if}

src/lib/devices/DeviceCard/DeviceRoutes/DeviceRouteAPI.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script context="module" lang="ts">
22
3-
export async function approveDeviceRoute(deviceID: string, routes: [string]): Promise<any> {
3+
export async function approveDeviceRoute(deviceID: string, routes: string[]): Promise<any> {
44
// variables in local storage
55
let headscaleURL = localStorage.getItem('headscaleURL') || '';
66
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';

0 commit comments

Comments
 (0)