2023-11-17 00:05:35 +00:00
|
|
|
<script lang="ts">
|
2023-11-30 20:53:37 +00:00
|
|
|
import { PUBLIC_BASE_URL } from '$lib/config';
|
2023-11-17 00:05:35 +00:00
|
|
|
|
2023-11-21 20:22:29 +00:00
|
|
|
import { Container, Row, Toast, ToastBody } 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-24 23:42:37 +00:00
|
|
|
const fetchStatusData = () => {
|
|
|
|
fetch(`${PUBLIC_BASE_URL}/api/status`)
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
status.set(data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchSettingsData = () => {
|
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-24 23:42:37 +00:00
|
|
|
};
|
2023-11-18 12:55:55 +00:00
|
|
|
|
2023-11-24 23:42:37 +00:00
|
|
|
onMount(() => {
|
|
|
|
fetchSettingsData();
|
|
|
|
fetchStatusData();
|
2023-11-18 12:55:55 +00:00
|
|
|
|
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
|
|
|
});
|
2023-11-21 20:22:29 +00:00
|
|
|
|
|
|
|
let toastIsOpen = false;
|
|
|
|
let toastColor = 'success';
|
|
|
|
let toastBody = '';
|
|
|
|
|
|
|
|
export const showToast = (event) => {
|
|
|
|
toastIsOpen = true;
|
|
|
|
toastColor = event.detail.color;
|
|
|
|
toastBody = event.detail.text;
|
|
|
|
};
|
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-24 23:42:37 +00:00
|
|
|
<Settings bind:settings on:showToast={showToast} on:formReset={fetchSettingsData}></Settings>
|
2023-11-17 00:05:35 +00:00
|
|
|
</Row>
|
|
|
|
</Container>
|
2023-11-21 20:22:29 +00:00
|
|
|
<div class="position-fixed bottom-0 end-0 p-2">
|
|
|
|
<div class="">
|
|
|
|
<Toast
|
|
|
|
isOpen={toastIsOpen}
|
|
|
|
class="me-1 bg-{toastColor}"
|
|
|
|
autohide
|
|
|
|
on:close={() => (toastIsOpen = false)}
|
|
|
|
>
|
|
|
|
<ToastBody>
|
|
|
|
{toastBody}
|
|
|
|
</ToastBody>
|
|
|
|
</Toast>
|
|
|
|
</div>
|
|
|
|
</div>
|