mirror of
https://github.com/smartyellow/status.git
synced 2025-01-18 13:37:59 +00:00
Debounce dashboard on:resize
Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
parent
8ab20c9e2e
commit
be51bba14d
@ -3,7 +3,7 @@
|
||||
import TileRawValue from './tile-rawvalue.svelte';
|
||||
import Settings from './settings.svelte';
|
||||
import { flip } from 'svelte/animate';
|
||||
import { proportionalGrid, settings, shuffle, ringBell } from './lib';
|
||||
import { settings, shuffle, ringBell } from './lib';
|
||||
|
||||
const [ send, receive ] = shuffle;
|
||||
let size = ($settings.cols || 4) * ($settings.rows || 3) - 1;
|
||||
@ -11,6 +11,28 @@
|
||||
let tiles = [];
|
||||
let time = '';
|
||||
let globalData = {};
|
||||
let resizeTimer;
|
||||
|
||||
function onResize() {
|
||||
clearTimeout(resizeTimer);
|
||||
resizeTimer = setTimeout(proportionalGrid, 750);
|
||||
}
|
||||
|
||||
function proportionalGrid() {
|
||||
const container = document.querySelector('.center');
|
||||
const w = container.clientWidth;
|
||||
const h = container.clientHeight;
|
||||
const tileW = 400;
|
||||
const tileH = 300;
|
||||
const availableCols = Math.floor(w / tileW);
|
||||
const availableRows = Math.floor(h / tileH);
|
||||
console.log(w, h, availableCols, availableRows);
|
||||
|
||||
settings.update({
|
||||
cols: availableCols,
|
||||
rows: availableRows,
|
||||
});
|
||||
}
|
||||
|
||||
function tileProps(service) {
|
||||
let props = {
|
||||
@ -65,6 +87,7 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
proportionalGrid();
|
||||
const ws = new WebSocket('ws://__SERVER__/statusdashboard/socket');
|
||||
|
||||
ws.onmessage = async evt => {
|
||||
@ -100,7 +123,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={proportionalGrid} />
|
||||
<svelte:window on:resize={onResize} />
|
||||
<Settings />
|
||||
|
||||
<div
|
||||
|
@ -63,19 +63,3 @@ export function formatDuration(ms) {
|
||||
.map(([ key, val ]) => `${val} ${key}`)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
export function proportionalGrid() {
|
||||
const container = document.querySelector('.center');
|
||||
const w = container.clientWidth;
|
||||
const h = container.clientHeight;
|
||||
const tileW = 400;
|
||||
const tileH = 300;
|
||||
const availableCols = Math.floor(w / tileW);
|
||||
const availableRows = Math.floor(h / tileH);
|
||||
console.log(w, h, availableCols, availableRows);
|
||||
|
||||
settings.update({
|
||||
cols: availableCols,
|
||||
rows: availableRows,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user