Skip to content

Commit

Permalink
fix top level await and fix broken device delete
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousm4x committed Jan 30, 2023
1 parent e07755f commit 7bdb99c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 87 deletions.
68 changes: 0 additions & 68 deletions backend/migrations/1675079520_updated_devices.go

This file was deleted.

5 changes: 3 additions & 2 deletions frontend/src/components/DeviceForm.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { goto } from '$app/navigation';
import { pocketbase } from '@stores/pocketbase';
import { pocketbase, devices } from '@stores/pocketbase';
import { faEye, faEyeSlash, faPlus, faTrashCan } from '@fortawesome/free-solid-svg-icons';
import Fa from 'svelte-fa';
Expand Down Expand Up @@ -73,10 +73,11 @@
async function deleteDevice() {
deleteButton.state = 'waiting';
try {
await $pocketbase.collection('devices').delete(device.id);
device.ports.forEach(async (port) => {
await $pocketbase.collection('ports').delete(port);
});
await $pocketbase.collection('devices').delete(device.id);
delete $devices[device.id];
goto('/');
} catch (error) {
clearTimeout(timeout);
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@
import { theme } from '@stores/theme';
import Navbar from '@components/Navbar.svelte';
import Transition from '@components/Transition.svelte';
import { pocketbase, settings, devices } from '@stores/pocketbase';
let preferesDark;
onMount(async () => {
let settingsRes = {};
settingsRes = await $pocketbase.collection('settings').getList(1, 1);
settings.set(settingsRes.items[0]);
let tempDevices = {};
const devicesRes = await $pocketbase.collection('devices').getFullList(200, {
sort: 'name',
expand: 'ports'
});
devicesRes.forEach((device) => {
tempDevices[device.id] = device;
});
devices.set(tempDevices);
});
onMount(() => {
// import bootstrap js
import('bootstrap/js/dist/dropdown');
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/routes/device/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
import DeviceForm from '@components/DeviceForm.svelte';
export let data;
let device = $devices[data.params.id];
if (!device?.expand?.ports) {
device.expand.ports = [];
let device;
$: {
device = $devices[data.params.id];
if (device && !device?.expand?.ports) {
device.expand.ports = [];
}
}
$:;
</script>
{#if device}
Expand Down
19 changes: 5 additions & 14 deletions frontend/src/stores/pocketbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,19 @@ import { writable } from 'svelte/store';
import PocketBase from 'pocketbase';

// set backend url based on environment
let backend_url = '';
let backend_url = '/';
let isDevMode = import.meta.env.DEV;
if (isDevMode) {
backend_url = 'http://127.0.0.1:8090';
} else {
backend_url = '/';
}

// get default values for stores
const pb = new PocketBase(backend_url);
pb.autoCancellation(false);
const settingsRes = await pb.collection('settings').getList(1, 1);
let tempDevices = {};
const devicesRes = await pb.collection('devices').getFullList(200, {
sort: 'name',
expand: 'ports'
});
devicesRes.forEach((device) => {
tempDevices[device.id] = device;
});

// export stores
export const pocketbase = writable(pb);
export const settings = writable(settingsRes.items[0]);
export const devices = writable(tempDevices);
export const settings = writable({
website_title: ''
});
export const devices = writable({});

0 comments on commit 7bdb99c

Please sign in to comment.