This repository has been archived on 2023-12-22. You can view files and clone it, but cannot push or open issues or pull requests.
old-monorepo/_Dashboard/app/renderer/components/LampButtonToggle.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-08-08 19:34:29 +02:00
import React, { useState, useEffect } from 'react';
2020-08-01 16:29:42 +02:00
import { useSelector } from 'react-redux/';
import Button from '@material-ui/core/Button';
import EmojiObjectsIcon from '@material-ui/icons/EmojiObjects';
export default function LampButtonToggle(props) {
//const comConnection = useSelector((state) => state.comConnectionReducer);
const comConnection = null;
2020-08-01 17:13:38 +02:00
const [comData, setComData] = useState('');
2020-08-08 19:34:29 +02:00
const comDataListener = (data) => {
2020-08-01 17:13:38 +02:00
setComData(data);
2020-08-08 19:34:29 +02:00
};
useEffect(() => {
comConnection.parser.on('data', comDataListener);
return () => {
comConnection.parser.removeListener('data', comDataListener);
};
}, []);
2020-08-01 17:13:38 +02:00
const lampEnabled = comData[props.lampnumber] === '1';
2020-08-08 19:34:29 +02:00
2020-08-01 16:29:42 +02:00
return (
<div>
<Button
2020-08-01 20:59:08 +02:00
style={{ height: 130, width: 130, marginLeft: 10, marginRight: 10 }}
2020-08-01 16:29:42 +02:00
variant="contained"
2020-08-01 17:13:38 +02:00
color={lampEnabled ? 'secondary' : 'primary'}
2020-08-01 16:29:42 +02:00
endIcon={<EmojiObjectsIcon />}
onClick={() => {
comConnection.port.write(String(props.lampnumber));
}}>
{`Lamp ${props.lampnumber}`}
</Button>
</div>
);
}