]> git.r.bdr.sh - rbdr/canvas/blobdiff - src/lib/components/sensor.svelte
Connect sensor to database
[rbdr/canvas] / src / lib / components / sensor.svelte
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e98b74086b30b208c3f349fc527f7ca6c3a0d736 100644 (file)
@@ -0,0 +1,35 @@
+<script>
+  import { browser } from '$app/env';
+  import { maxSize } from '$lib/config';
+  import { sensor } from '$lib/stores/widgets';
+
+  export let x;
+  export let y;
+
+  const kSensorSize = 2;
+
+  let left;
+  let right;
+  let top;
+  let bottom;
+
+  let timer;
+  const fetchItems = function fetchItems( left, top, right, bottom ) {
+    clearTimeout(timer);
+               timer = setTimeout(() => {
+      sensor.set({ left, top, right, bottom });
+               }, 50);
+  }
+
+  $: {
+    if (browser) {
+      left = x - window.screen.width * kSensorSize;
+      top = y - window.screen.height * kSensorSize;
+      right = x + window.screen.width * kSensorSize;
+      bottom = y + window.screen.height * kSensorSize;
+
+      fetchItems(left, top, right, bottom);
+    }
+  }
+
+</script>