"use client"; import { useEffect, useRef, useState } from "react"; import styled from "styled-components"; import { Button, Col, Collapse, Icon, Menu, Modal, PopConfirm, Row, ScrollIndicator, Slider, SplitButton, Transfer } from "tiny-ui"; import WLED from "./WLED.js"; const { Panel } = Collapse; const to255 = (v) => Math.ceil((v / 100) * 255); const from255 = (v) => Math.ceil((v / 255) * 100); const download = (filename, data, type = "application/json") => { const blob = new Blob([data], { type: type }); const href = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = href; link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; const StyledRow = styled((props) => )` margin: 0.25rem 0.5rem; & .action { text-align: right; & .ty-icon { margin-right: 1rem; } } `; const StyledMenu = styled((props) => )` & .ty-icon { margin-right: 1rem; } `; const ScrollingDiv = (props) => { const targetRef = useRef(null); return ( <> targetRef?.current} />
); }; const UploadModal = ({ data, client, onConfirm, ...rest }) => { const [payload, setPayload] = useState({}); useEffect(() => { if (data) setPayload({ ...data }); }, [data]); const handleConfirm = (_) => { onConfirm(payload); }; const handleChange = (e) => { const fileReader = new FileReader(); fileReader.readAsText(e?.target?.files?.[0], "UTF-8"); fileReader.onload = (e) => { if (e?.target?.result) { console.log("payload", { ...payload, value: JSON.parse(e?.target?.result) }); setPayload({ ...payload, value: JSON.parse(e?.target?.result) }); } }; }; if (!data) return null; return (
Are you sure you want to upload and override presets?
{payload?.value ? (
{JSON.stringify(payload?.value, null, 2)}
) : null}
); }; const PurgeModal = ({ data, client, onConfirm, ...rest }) => { const [payload, setPayload] = useState({}); useEffect(() => { if (data) setPayload({ ...data }); }, [data]); const handleConfirm = (_) => { onConfirm(payload); }; if (!data) return null; return (
Are you sure you want to delete these presets?
{JSON.stringify(data?.value, null, 2)}
); }; const CopyModal = ({ data, client, clients, onConfirm, ...rest }) => { const [transfer, setTransfer] = useState({}); const [payload, setPayload] = useState({}); useEffect(() => { setPayload({ ...payload, value: data }); }, [data]); useEffect(() => { if (clients) setTransfer( clients ?.filter((o) => o !== client) ?.map((o, i) => ({ key: o, label: o })) ); }, [clients, client]); const handleConfirm = (_) => { onConfirm(payload); }; if (!data) return null; return (
{JSON.stringify(data, null, 2)}
{ setPayload({ ...payload, clients: value }); }} />
); }; const InstanceManagement = ({ client, presets, onCopy, onPreset, onDelete }) => { if (!presets) return null; return Object.keys(presets)?.map((o, i) => ( {presets[o]?.name || ""} { download( `preset_${o}.json`, JSON.stringify(presets[o], null, 2) ); }} > Save { onCopy({ [o]: presets[o] }); }} > Copy onDelete({ clients: [client], value: [o] })} > Delete } onClick={(e) => { onPreset({ clients: [client], value: o }); }} > )); }; const StateMangement = ({ client, setPurge, setUpload, setCopy, onPower, onSync, onBrightness, onPreset, onDefaults, current, ...props }) => { if (!current) return null; return (