'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`