2023-11-17 00:05:35 +00:00
|
|
|
<script lang="ts">
|
2023-11-19 19:27:22 +00:00
|
|
|
import { PUBLIC_BASE_URL } from '$env/static/public';
|
2023-11-17 00:05:35 +00:00
|
|
|
|
2023-11-19 19:27:22 +00:00
|
|
|
import { Container, Row } from 'sveltestrap';
|
2023-11-17 00:05:35 +00:00
|
|
|
|
2023-11-19 19:27:22 +00:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
import { writable } from 'svelte/store';
|
2023-11-17 00:05:35 +00:00
|
|
|
import Control from './Control.svelte';
|
|
|
|
import Settings from './Settings.svelte';
|
2023-11-19 19:27:22 +00:00
|
|
|
import Status from './Status.svelte';
|
2023-11-17 00:05:35 +00:00
|
|
|
|
2023-11-17 02:15:23 +00:00
|
|
|
let settings = writable({
|
2023-11-19 19:27:22 +00:00
|
|
|
fgColor: '0'
|
|
|
|
});
|
2023-11-17 00:05:35 +00:00
|
|
|
|
2023-11-18 12:55:55 +00:00
|
|
|
let status = writable({
|
2023-11-19 19:27:22 +00:00
|
|
|
data: ['L', 'O', 'A', 'D', 'I', 'N', 'G'],
|
|
|
|
espFreeHeap: 0,
|
|
|
|
espHeapSize: 0,
|
|
|
|
connectionStatus: {
|
|
|
|
price: false,
|
|
|
|
blocks: false
|
|
|
|
},
|
2023-11-18 12:55:55 +00:00
|
|
|
leds: []
|
2023-11-19 19:27:22 +00:00
|
|
|
});
|
2023-11-18 12:55:55 +00:00
|
|
|
|
2023-11-17 00:05:35 +00:00
|
|
|
onMount(() => {
|
2023-11-19 19:27:22 +00:00
|
|
|
fetch(PUBLIC_BASE_URL + `/api/settings`)
|
2023-11-17 00:05:35 +00:00
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
data.fgColor = String(data.fgColor);
|
|
|
|
data.bgColor = String(data.bgColor);
|
2023-11-19 19:27:22 +00:00
|
|
|
data.timePerScreen = data.timerSeconds / 60;
|
2023-11-17 02:15:23 +00:00
|
|
|
|
2023-11-19 19:27:22 +00:00
|
|
|
if (data.fgColor > 65535) {
|
|
|
|
data.fgColor = '65535';
|
|
|
|
}
|
2023-11-17 12:12:22 +00:00
|
|
|
|
2023-11-19 19:27:22 +00:00
|
|
|
if (data.bgColor > 65535) {
|
|
|
|
data.bgColor = '65535';
|
|
|
|
}
|
2023-11-17 00:05:35 +00:00
|
|
|
settings.set(data);
|
|
|
|
});
|
2023-11-18 12:55:55 +00:00
|
|
|
|
|
|
|
fetch(`${PUBLIC_BASE_URL}/api/status`)
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
status.set(data);
|
|
|
|
});
|
|
|
|
|
2023-11-19 19:27:22 +00:00
|
|
|
const evtSource = new EventSource(`${PUBLIC_BASE_URL}/events`);
|
2023-11-18 12:55:55 +00:00
|
|
|
|
2023-11-19 19:27:22 +00:00
|
|
|
evtSource.addEventListener('status', (e) => {
|
|
|
|
let dataObj = JSON.parse(e.data);
|
|
|
|
status.set(dataObj);
|
|
|
|
});
|
2023-11-17 00:05:35 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-11-17 18:10:46 +00:00
|
|
|
<svelte:head>
|
|
|
|
<title>₿TClock</title>
|
|
|
|
</svelte:head>
|
|
|
|
|
2023-11-17 00:05:35 +00:00
|
|
|
<Container fluid>
|
|
|
|
<Row>
|
2023-11-18 12:55:55 +00:00
|
|
|
<Control bind:settings bind:status></Control>
|
2023-11-19 19:27:22 +00:00
|
|
|
<Status bind:settings bind:status></Status>
|
2023-11-17 00:05:35 +00:00
|
|
|
<Settings bind:settings></Settings>
|
|
|
|
</Row>
|
|
|
|
</Container>
|