'use strict'; import { h, html, render, useEffect, useState } from './preact.min.js'; const Configuration = function (props) { const [url, setUrl] = useState(props.config.url || ''); const [pub, setPub] = useState(props.config.pub || ''); const [sub, setSub] = useState(props.config.sub || ''); useEffect(() => { setUrl(props.config.url); setPub(props.config.pub); setSub(props.config.sub); }, [props.config]); const update = (name, val) => fetch('/api/config/set', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ [name]: val }) }) .catch(err => { console.log(err); enable(false); }); const updateurl = ev => update('url', url); const updatepub = ev => update('pub', pub); const updatesub = ev => update('sub', sub); return html`

Device Configuration

MQTT server: setUrl(ev.target.value)} />
Subscribe topic: setSub(ev.target.value)} />
Publish topic: setPub(ev.target.value)} />
`; }; const App = function (props) { const [config, setConfig] = useState({}); const getconfig = () => fetch('/api/config/get') .then(r => r.json()) .then(r => setConfig(r)) .catch(err => console.log(err)); useEffect(() => { getconfig(); }, []); return html`

Basic Preact-based UI demo

${h(Configuration, { config })}
`; }; window.onload = () => render(h(App), document.body);