mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-07-24 06:24:07 -04:00
improve ts
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
import type { Record } from 'pocketbase';
|
||||
|
||||
export type Device = Record & {
|
||||
name: string;
|
||||
ip: string;
|
||||
mac: string;
|
||||
netmask: string;
|
||||
status: string;
|
||||
ports: string[];
|
||||
link: URL;
|
||||
wake_cron: string;
|
||||
wake_cron_enabled: boolean;
|
||||
shutdown_cron: string;
|
||||
shutdown_cron_enabled: boolean;
|
||||
shutdown_cmd: string;
|
||||
password: string;
|
||||
groups: Group[];
|
||||
expand: {
|
||||
ports: Record[];
|
||||
ports: Port[];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -10,3 +24,7 @@ export type Port = Record & {
|
||||
name: string;
|
||||
number: number;
|
||||
};
|
||||
|
||||
export type Group = Record & {
|
||||
name: string;
|
||||
};
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
export type SettingsPublic = {
|
||||
import type { Record } from 'pocketbase';
|
||||
|
||||
export type SettingsPublic = Record & {
|
||||
collectionId: string;
|
||||
favicon: string;
|
||||
setup_completed: boolean;
|
||||
website_title: string;
|
||||
};
|
||||
|
||||
export type SettingsPrivate = {
|
||||
export type SettingsPrivate = Record & {
|
||||
interval: number;
|
||||
scan_range: string;
|
||||
};
|
||||
|
||||
@@ -8,21 +8,17 @@
|
||||
import Navbar from '$lib/components/Navbar.svelte';
|
||||
import Transition from '$lib/components/Transition.svelte';
|
||||
import type { Device } from '$lib/types/device';
|
||||
import type { SettingsPublic } from '$lib/types/settings';
|
||||
|
||||
onMount(async () => {
|
||||
// set settingsPub store on load
|
||||
if (!$settingsPub) {
|
||||
const res = await $pocketbase.collection('settings_public').getList(1, 1);
|
||||
settingsPub.set({
|
||||
collectionId: res.items[0].collectionId,
|
||||
favicon: res.items[0].favicon,
|
||||
setup_completed: res.items[0].setup_completed,
|
||||
website_title: res.items[0].website_title
|
||||
});
|
||||
settingsPub.set(res.items[0] as SettingsPublic);
|
||||
}
|
||||
|
||||
// redirect to welcome page if setup is not completed
|
||||
if (!$settingsPub?.setup_completed && $page.url.pathname !== '/welcome') {
|
||||
if (!$settingsPub.setup_completed && $page.url.pathname !== '/welcome') {
|
||||
goto('/welcome');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import DeviceCard from '$lib/components/DeviceCard.svelte';
|
||||
import { pocketbase, devices } from '$lib/stores/pocketbase';
|
||||
import type { Device } from '$lib/types/device';
|
||||
import { onMount } from 'svelte';
|
||||
import type { Device, Port } from '$lib/types/device';
|
||||
|
||||
onMount(() => {
|
||||
$pocketbase.collection('devices').subscribe('*', (e) => {
|
||||
@@ -36,7 +36,7 @@
|
||||
})
|
||||
);
|
||||
if (deviceIndex !== -1 && portIndex !== -1) {
|
||||
$devices[deviceIndex].expand.ports[portIndex] = e.record;
|
||||
$devices[deviceIndex].expand.ports[portIndex] = e.record as Port;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user