Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
add live reload to overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
kclejeune committed Aug 31, 2021
1 parent c2d45ab commit eee9f09
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/lib/components/ui/Dropdown.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script lang="ts">
export let options: any[];
export let selected: any = undefined;
export let open: boolean = false;
export let displayWith: (value: any) => any = undefined;
if (!displayWith) {
displayWith = (value) => value;
}
</script>

<div class="dropdown dropdown-hover {open ? 'dropdown-open' : ''}">
{#if $$slots.default}
<div tabindex="0" class="m-1 btn"><slot /></div>
{/if}
<ul tabindex="0" class="p-2 shadow menu dropdown-content bg-base-100 rounded-box w-52">
{#each options as option}
<li on:click={() => (selected = option)}>
<a>{displayWith(option)}</a>
</li>
{/each}
</ul>
</div>
19 changes: 19 additions & 0 deletions src/lib/components/ui/Menu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
export let options: any[];
export let selected: any = undefined;
export let displayWith: (value: any) => any = undefined;
if (!displayWith) {
displayWith = (value) => `${value}s`;
}
</script>

<ul class="menu py-3 bg-base-300 rounded-box horizontal">
<li class="menu-title">
<span><slot /></span>
</li>
{#each options as option}
<li on:click={() => (selected = option)}>
<a class="rounded-lg {selected === option ? 'bg-primary' : ''}">{displayWith(option)}</a>
</li>
{/each}
</ul>
12 changes: 12 additions & 0 deletions src/lib/components/ui/Toggle.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts">
export let active: boolean = false;
export let color: 'toggle-primary' | 'toggle-secondary' | 'toggle-accent' | '' = 'toggle-primary';
</script>

<span class="form-control inline-flex">
<span class="m-2"><slot /></span>

<span class="m-2">
<input type="checkbox" checked={active} class="toggle {color}" />
</span>
</span>
15 changes: 12 additions & 3 deletions src/routes/overview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
Cell5GStat,
CellRadioStat,
} from '$lib/types';
export async function load({ fetch }) {
export async function load({ fetch, session }) {
session['refresh'] = '0';
const status: StatusResponse = await fetch(`/api/${Endpoint.STATUS}`).then((res: Response) =>
res.json(),
);
Expand Down Expand Up @@ -58,7 +59,11 @@
import H1 from '$lib/components/ui/H1.svelte';
import DeviceInformation from '$lib/widgets/DeviceInformation.svelte';
import NetworkInformation from '$lib/widgets/NetworkInformation.svelte';
import { onDestroy } from 'svelte';
import { onDestroy, onMount } from 'svelte';
import { page, session } from '$app/stores';
import Toggle from '$lib/components/ui/Toggle.svelte';
import Dropdown from '$lib/components/ui/Dropdown.svelte';
import Menu from '$lib/components/ui/Menu.svelte';
export let routerCfg: DeviceAppStatus;
export let devices: DeviceCfg[];
Expand All @@ -72,12 +77,16 @@
routerCfg.UpTime++;
}, 1000);
let refreshInterval = setInterval(() => {
$session['refresh'] = `${routerCfg.UpTime}`;
}, 5000);
onDestroy(() => {
clearInterval(uptimeInterval);
clearInterval(refreshInterval);
});
</script>

<H1>Overview</H1>
<H1>Overview <button class="btn loading btn-circle btn-lg bg-base-200 btn-ghost"></button></H1>

<div class="grid gap-4 m-4 md:grid-cols-2 lg:grid-cols-3">
<div class="col-auto">
Expand Down

0 comments on commit eee9f09

Please sign in to comment.