import { render } from 'preact' import { useEffect, useState } from 'preact/hooks' import { MessageWidget } from './components/MessageWidget.jsx' import { PieChartWidget } from './components/PieChartWidget.jsx' import { useUser } from './util.js' const WidgetTypes = { pie: PieChartWidget, message: MessageWidget, } const Widget = ({ type, value }) => { const CustomWidget = WidgetTypes[type] return (
) } const App = () => { const user = useUser() const [widgets, setWidgets] = useState([]) useEffect(() => { fetch('/api/dashboard-state') .then(res => res.json()) .then(state => setWidgets(state.widgets)) .catch(e => console.error(e)) }, []) return ( <>
space.phc.dm.unipi.it

(Viewing page as {user})

{widgets.map(w => ( ))}
) } render(, document.querySelector('main'))