"use client"; import { useEffect, useState } from "react"; import { Col, Loader, Row } from "tiny-ui"; import { WLEDClient } from "wled-client"; import { Automation, Layout } from "components"; import automation from "data/automation.json"; import presets from "data/presets.json"; const CLIENTS = process.env.CLIENTS || []; const NAMES = process.env.NAMES || []; export default function Home() { const [names, setNames] = useState(null); const [clients, setClients] = useState(null); const [connections, setConnections] = useState(null); useEffect(() => { let t = []; let c = []; let n = []; for (let client of CLIENTS) { c.push(client); t.push(new WLEDClient(client)); } for (let name of NAMES) { n.push(name); } setClients(c); setConnections(t); setNames(n); }, []); const handleSync = async (payload) => { if (payload?.clients && payload?.value) { for (let client of payload?.clients) { let indx = clients.findIndex((o) => o === client); if (connections[indx]) { let wled = connections[indx]; switch (payload?.value) { case "enable": await wled.enableUDPSync({ send: true, receive: false }); break; case "disable": await wled.disableUDPSync(); break; } } } } }; const handlePower = async (payload) => { if (payload?.clients && payload?.value) { for (let client of payload?.clients) { let indx = clients.findIndex((o) => o === client); if (connections[indx]) { let wled = connections[indx]; switch (payload?.value) { case "on": await wled.turnOn(); break; case "off": await wled.turnOff(); break; } } } } }; const handlePreset = async (payload) => { if (payload?.clients && payload?.value) { for (let client of payload?.clients) { let indx = clients.findIndex((o) => o === client); if (connections[indx]) { let wled = connections[indx]; await wled.setPreset(payload?.value); } } } }; return ( {(connections && clients && ( )) || } ); return; }