|
|
@@ -5,10 +5,10 @@ import { useEffect, useState } from "react";
|
|
|
import { Collapse, Loader } from "tiny-ui";
|
|
|
import { WLEDClient } from "wled-client";
|
|
|
|
|
|
-import { Layout, Management } from "components";
|
|
|
+import { Layout, Management, Notification } from "components";
|
|
|
|
|
|
-const CLIENTS = process.env.CLIENTS || [];
|
|
|
-const NAMES = process.env.NAMES || [];
|
|
|
+import config from "data/config.json";
|
|
|
+import defaults from "data/presets.json";
|
|
|
|
|
|
export default function Home() {
|
|
|
const [names, setNames] = useState(null);
|
|
|
@@ -19,20 +19,52 @@ export default function Home() {
|
|
|
let t = [];
|
|
|
let c = [];
|
|
|
let n = [];
|
|
|
- for (let client of CLIENTS) {
|
|
|
+ for (let client of Object.keys(config)) {
|
|
|
c.push(client);
|
|
|
+ n.push(config[client]);
|
|
|
t.push(new WLEDClient(client));
|
|
|
}
|
|
|
- for (let name of NAMES) {
|
|
|
- n.push(name);
|
|
|
- }
|
|
|
setClients(c);
|
|
|
setConnections(t);
|
|
|
setNames(n);
|
|
|
}, []);
|
|
|
|
|
|
+ const handleDefaults = async (payload) => {
|
|
|
+ if (payload?.clients) {
|
|
|
+ Notification({
|
|
|
+ type: "loading",
|
|
|
+ title: "Default presets installing",
|
|
|
+ description: `Sending data to ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
+ for (let client of payload.clients) {
|
|
|
+ let indx = clients.findIndex((o) => o === client);
|
|
|
+ if (connections[indx]) {
|
|
|
+ let wled = connections[indx];
|
|
|
+ for (let n of Object.keys(defaults)) {
|
|
|
+ if (n && defaults?.[n]) {
|
|
|
+ await wled.savePreset(n, defaults?.[n]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await wled.reinit();
|
|
|
+ }
|
|
|
+ Notification({
|
|
|
+ type: "success",
|
|
|
+ title: "Default presets installed",
|
|
|
+ description: `Default presets installed on ${payload?.clients?.join(
|
|
|
+ ", "
|
|
|
+ )}`
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const handleCopy = async (payload) => {
|
|
|
if (payload?.clients && payload?.value) {
|
|
|
+ Notification({
|
|
|
+ type: "loading",
|
|
|
+ title: "Copying presets",
|
|
|
+ description: `Sending data to ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
for (let client of payload.clients) {
|
|
|
let indx = clients.findIndex((o) => o === client);
|
|
|
if (connections[indx]) {
|
|
|
@@ -46,11 +78,25 @@ export default function Home() {
|
|
|
await wled.reinit();
|
|
|
}
|
|
|
}
|
|
|
+ Notification({
|
|
|
+ type: "success",
|
|
|
+ title: "Presets copied",
|
|
|
+ description: `Presets ${Object.keys(payload?.value)?.join(
|
|
|
+ ", "
|
|
|
+ )} copied to ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const handleDelete = async (payload) => {
|
|
|
if (payload?.clients && payload?.value) {
|
|
|
+ Notification({
|
|
|
+ type: "loading",
|
|
|
+ title: "Deleting presets",
|
|
|
+ description: `Sending delete requests to ${payload?.clients?.join(
|
|
|
+ ", "
|
|
|
+ )}`
|
|
|
+ });
|
|
|
for (let client of payload?.clients) {
|
|
|
let indx = clients.findIndex((o) => o === client);
|
|
|
if (connections[indx]) {
|
|
|
@@ -61,11 +107,23 @@ export default function Home() {
|
|
|
await wled.reinit();
|
|
|
}
|
|
|
}
|
|
|
+ Notification({
|
|
|
+ type: "success",
|
|
|
+ title: "Deleted presets",
|
|
|
+ description: `Presets ${Object.keys(payload?.value)?.join(
|
|
|
+ ", "
|
|
|
+ )} deleted from ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const handleSync = async (payload) => {
|
|
|
if (payload?.clients) {
|
|
|
+ Notification({
|
|
|
+ type: "loading",
|
|
|
+ title: "Sync update",
|
|
|
+ description: `Sending sync updates to ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
for (let client of payload?.clients) {
|
|
|
let indx = clients.findIndex((o) => o === client);
|
|
|
if (connections[indx]) {
|
|
|
@@ -81,11 +139,21 @@ export default function Home() {
|
|
|
await wled.reinit();
|
|
|
}
|
|
|
}
|
|
|
+ Notification({
|
|
|
+ type: "success",
|
|
|
+ title: `Sync ${payload?.value}`,
|
|
|
+ description: `Sync ${payload?.value} on ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const handlePower = async (payload) => {
|
|
|
if (payload?.clients && payload?.value) {
|
|
|
+ Notification({
|
|
|
+ type: "loading",
|
|
|
+ title: "Power updates",
|
|
|
+ description: `Sending power updates to ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
for (let client of payload?.clients) {
|
|
|
let indx = clients.findIndex((o) => o === client);
|
|
|
if (connections[indx]) {
|
|
|
@@ -112,11 +180,23 @@ export default function Home() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ Notification({
|
|
|
+ type: "success",
|
|
|
+ title: `Power ${payload?.value}`,
|
|
|
+ description: `Power ${payload?.value} run on ${payload?.clients?.join(
|
|
|
+ ", "
|
|
|
+ )}`
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const handleBrightness = async (payload) => {
|
|
|
if (payload?.clients && payload?.value) {
|
|
|
+ Notification({
|
|
|
+ type: "loading",
|
|
|
+ title: "Adjusting brightness",
|
|
|
+ description: `Adjusting brightness on ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
for (let client of payload?.clients) {
|
|
|
let indx = clients.findIndex((o) => o === client);
|
|
|
if (connections[indx]) {
|
|
|
@@ -125,12 +205,24 @@ export default function Home() {
|
|
|
await wled.reinit();
|
|
|
}
|
|
|
}
|
|
|
+ Notification({
|
|
|
+ type: "success",
|
|
|
+ title: `Brightness set`,
|
|
|
+ description: `Brightness set to ${
|
|
|
+ payload?.value
|
|
|
+ } on ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
const debounceHandleBrightness = debounce(handleBrightness, 500);
|
|
|
|
|
|
const handlePreset = async (payload) => {
|
|
|
if (payload?.clients && payload?.value) {
|
|
|
+ Notification({
|
|
|
+ type: "loading",
|
|
|
+ title: "Setting preset",
|
|
|
+ description: `Setting preset on ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
for (let client of payload?.clients) {
|
|
|
let indx = clients.findIndex((o) => o === client);
|
|
|
if (connections[indx]) {
|
|
|
@@ -139,6 +231,13 @@ export default function Home() {
|
|
|
await wled.reinit();
|
|
|
}
|
|
|
}
|
|
|
+ Notification({
|
|
|
+ type: "success",
|
|
|
+ title: `Preset set`,
|
|
|
+ description: `Preset set to ${
|
|
|
+ payload?.value
|
|
|
+ } on ${payload?.clients?.join(", ")}`
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -160,6 +259,7 @@ export default function Home() {
|
|
|
onPower={handlePower}
|
|
|
onBrightness={debounceHandleBrightness}
|
|
|
onPreset={handlePreset}
|
|
|
+ onDefaults={handleDefaults}
|
|
|
/>
|
|
|
))}
|
|
|
</Collapse>
|