From 276b7e48afeb767fa4a6547dacbb5db842c56ee1 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Mon, 11 Jul 2022 15:00:05 +0200 Subject: [PATCH] Dashboard settings using localStorage Signed-off-by: Romein van Buren --- gui/dashboard/app.css | 31 ++++++++++++++ gui/dashboard/index.js | 21 ++++++++-- gui/dashboard/modal.svelte | 8 ++++ gui/dashboard/settings.svelte | 57 +++++++++++++++++++++++++- index.js | 4 +- {dashboard => lib/dashboard}/build.js | 2 +- {dashboard => lib/dashboard}/socket.js | 0 7 files changed, 115 insertions(+), 8 deletions(-) rename {dashboard => lib/dashboard}/build.js (96%) rename {dashboard => lib/dashboard}/socket.js (100%) diff --git a/gui/dashboard/app.css b/gui/dashboard/app.css index 855af77..6131c3e 100644 --- a/gui/dashboard/app.css +++ b/gui/dashboard/app.css @@ -4,6 +4,7 @@ html, body { --grey: grey; --red: red; --green: green; + --dark: #0a0a0a; --radius: 10px; --cols: 4; --rows: 3; @@ -18,6 +19,11 @@ html, body { .theme-light { --body-bg: #fff; --tile-bg: #dedede; + --dark: #c2c2c2; +} + +.mb { + margin-bottom: 1rem; } button { @@ -28,4 +34,29 @@ button { appearance: none; padding: 1rem; color: inherit; + font: inherit; +} + +.btn { + border: 1px solid var(--dark); + padding: 0.7rem; + border-radius: var(--radius); +} + +.btn:hover { + background-color: var(--dark); +} + +label { + display: block; + margin-bottom: 1rem; +} + +label input, +label select { + display: block; + width: 100%; + margin-top: 0.5rem; + font-size: 1rem; + font-family: inherit; } diff --git a/gui/dashboard/index.js b/gui/dashboard/index.js index 45e9bf5..68a1638 100644 --- a/gui/dashboard/index.js +++ b/gui/dashboard/index.js @@ -1,8 +1,21 @@ +import { get, writable } from 'svelte/store'; import App from './app.svelte'; -import { writable } from 'svelte-local-storage-store'; new App({ target: document.body }); -export const settings = writable('settings', { - theme: 'dark', -}); +function createSettingsStore() { + const s = writable(0); + + function updateStorage(val) { + window.localStorage.setItem('statusdash', JSON.stringify(val)); + s.set(val); + } + + return { + subscribe: s.subscribe, + set: val => updateStorage(val), + update: val => updateStorage({ ...get(s), val }), + }; +} + +export const settings = createSettingsStore(); diff --git a/gui/dashboard/modal.svelte b/gui/dashboard/modal.svelte index 72e1f00..903178c 100644 --- a/gui/dashboard/modal.svelte +++ b/gui/dashboard/modal.svelte @@ -52,11 +52,19 @@ .header { display: flex; align-items: center; + border-bottom: 1px solid var(--dark); } .header button.close { margin-left: auto; overflow-y: auto; + font-size: 1.5rem; + border-radius: var(--radius); + border-radius: 0 var(--radius) 0 0; + } + + .header button.close:hover { + background-color: var(--dark); } .header .title { diff --git a/gui/dashboard/settings.svelte b/gui/dashboard/settings.svelte index 9052447..6e54a97 100644 --- a/gui/dashboard/settings.svelte +++ b/gui/dashboard/settings.svelte @@ -1,11 +1,39 @@ {#if !open} @@ -17,7 +45,24 @@ {/if} - hi +
+ +
+ +
diff --git a/index.js b/index.js index dfaa8d0..2f167b2 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,8 @@ const { fork } = require('child_process'); const { processOutage } = require('./lib/processoutage'); -const buildDashboard = require('./dashboard/build'); -const createDashboardSocket = require('./dashboard/socket'); +const buildDashboard = require('./lib/dashboard/build'); +const createDashboardSocket = require('./lib/dashboard/socket'); const { minifyHtml } = require('core/strings'); const { readFile } = require('fs/promises'); diff --git a/dashboard/build.js b/lib/dashboard/build.js similarity index 96% rename from dashboard/build.js rename to lib/dashboard/build.js index cc46d4d..7eb0b7c 100644 --- a/dashboard/build.js +++ b/lib/dashboard/build.js @@ -17,7 +17,7 @@ async function build({ server, settings }) { try { const bundle = await rollup({ - input: __dirname + '/../gui/dashboard/index.js', + input: __dirname + '/../../gui/dashboard/index.js', plugins: [ // Svelte svelte({ diff --git a/dashboard/socket.js b/lib/dashboard/socket.js similarity index 100% rename from dashboard/socket.js rename to lib/dashboard/socket.js