The main server, and probably only repository in this org.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1 KiB

Squashed commit of the following: commit 042130f11c6f807d128e2ffbdb76f4be2170a43f Author: Stian Aune <post@stian-aune.com> Date: Wed Apr 10 22:16:14 2019 +0200 Done? commit 3089c6f8be3135ab1aa2b95b9314a753596714a7 Author: Stian Aune <post@stian-aune.com> Date: Wed Mar 27 22:20:07 2019 +0100 Bugfix + some unit tests bc why not? commit 38f874b5538a7d9563b44d60b2fa881d941defc8 Author: Stian Aune <post@stian-aune.com> Date: Tue Mar 26 22:14:22 2019 +0100 Front page. commit 5bdf2a0c48e0e388bffb53714b0410ebd3f8b8e7 Author: Stian Aune <post@stian-aune.com> Date: Thu Mar 7 21:10:57 2019 +0100 Rename groups and stuff. commit 3130710b198c434fe312ea3123cbe5ba3fb526b7 Merge: 118a21a fa98a0b Author: Stian Aune <post@stian-aune.com> Date: Thu Mar 7 21:06:16 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit 118a21ad42adaa4968318b1e798a58f0565db849 Author: Stian Aune <post@stian-aune.com> Date: Thu Mar 7 21:06:02 2019 +0100 I can a lot of things. commit 089ee6816986e06e77eff404eaa9f04cda0e4275 Merge: 0a6cc16 f27c0a3 Author: Stian Aune <post@stian-aune.com> Date: Tue Mar 5 22:13:41 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit 0a6cc16e0fda482c04dd88c658273c2774b50d7a Author: Stian Aune <post@stian-aune.com> Date: Tue Mar 5 22:13:31 2019 +0100 More stuff. commit 1ef2623637f2f7c852edffa7914c2095a990539b Author: Stian Aune <post@stian-aune.com> Date: Sun Mar 3 21:59:23 2019 +0100 Add/remove group. commit 59240ce22d305b2b335dd46bb5f528f720b5eedc Merge: 537e86c e11ba33 Author: Stian Aune <post@stian-aune.com> Date: Sun Mar 3 21:15:06 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit 537e86cced5ab9b8919aaa0f89b277ed9ecdde27 Author: Stian Aune <post@stian-aune.com> Date: Sun Mar 3 21:14:55 2019 +0100 For reals. commit de5fb0d16ddde159a54ce7bb2af09eb4a87960c2 Author: Stian Aune <post@stian-aune.com> Date: Sun Mar 3 21:14:30 2019 +0100 Modal cleanup + light page. commit 01daa2800085df9799de4890a3574ef405b1ec89 Author: Stian Aune <post@stian-aune.com> Date: Sun Feb 24 00:27:36 2019 +0100 Hmm... commit be2fe56e62a212e2691288f5db0a2d826719689d Merge: 99867a5 22dddc7 Author: Stian Aune <post@stian-aune.com> Date: Sat Feb 23 15:16:07 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit 99867a5fd680e7bd2489df4a01a5609d1e7867d5 Author: Stian Aune <post@stian-aune.com> Date: Sat Feb 23 15:16:02 2019 +0100 WIP. commit d82bbf53f84ab3c47814e5d586400c34787be4d6 Author: Stian Aune <post@stian-aune.com> Date: Tue Feb 19 21:37:59 2019 +0100 WIP. commit 7ed6d2148dcd991050bbc2ecfaef6fc42a0dc4ce Author: Stian Aune <mail@stian-aune.com> Date: Sun Feb 10 13:30:53 2019 +0100 Stuffs. commit ee9a3d485efcf3cf7308a30e4bea27b97002324e Author: Stian Aune <mail@stian-aune.com> Date: Sun Feb 10 12:29:47 2019 +0100 Bleurgh. commit 59ef68ad8f8ce1e05e81c4322bad52cb319cd716 Author: Stian Aune <post@stian-aune.com> Date: Thu Feb 7 21:15:37 2019 +0100 Thursday night commit. commit ee3ff503427fd86306e88bdd4b857690c38f07f4 Merge: daf071a e644f48 Author: Stian Aune <post@stian-aune.com> Date: Wed Feb 6 22:02:37 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit daf071a4429f5e0158c88e6b142659b6ad6c851a Author: Stian Aune <post@stian-aune.com> Date: Mon Feb 4 20:56:45 2019 +0100 Rewrote light tests. commit edffa49d18ad07b652e5f9d72bd350bd499144a9 Merge: 83052a2 8c302ec Author: Stian Aune <post@stian-aune.com> Date: Mon Feb 4 20:31:26 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit 83052a2ab8d2b51c3003417142ba15ce1ed06921 Author: Stian Aune <post@stian-aune.com> Date: Mon Feb 4 20:31:22 2019 +0100 Blah. commit aec6cd0b7d5aa812b907b16e1c65687e94e16866 Merge: e6fefb5 0503f79 Author: Stian Aune <post@stian-aune.com> Date: Tue Jan 29 21:06:24 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit e6fefb5bd1fc487b32515ee5041cd42b37058d52 Merge: 97f7a78 eca8a30 Author: Stian Aune <post@stian-aune.com> Date: Mon Jan 28 22:44:19 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit 97f7a78f3f72331996eee63c7623d04272bc1d71 Merge: 195738d 174b818 Author: Stian Aune <post@stian-aune.com> Date: Sun Jan 13 13:20:10 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit 195738d6eddde94f7ca60a2d9b5ea086a204aa7f Merge: a2f2c2b 2e3e120 Author: Stian Aune <post@stian-aune.com> Date: Sat Jan 12 17:24:00 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit a2f2c2b0bce7d8f54f851dd14d527763390b0123 Merge: edd629e 9004f2f Author: Stian Aune <post@stian-aune.com> Date: Mon Jan 7 20:58:37 2019 +0100 Merge remote-tracking branch 'origin/master' into webui commit edd629eb395af92b250cef9bb452952eded115aa Author: Stian Aune <post@stian-aune.com> Date: Mon Jan 7 20:58:32 2019 +0100 More stuff. commit 206d5005db09f3a149b9dccf9fff886b44252394 Author: Stian Aune <post@stian-aune.com> Date: Mon Jan 7 19:11:03 2019 +0100 Cleanup.
5 years ago
  1. import React, {useEffect, useState} from "react";
  2. import useLights from "../Hooks/light";
  3. import {Card, CardBody, CardHeader, Col, CustomInput, FormGroup} from "reactstrap";
  4. import ColorPicker from "./Misc/ColorPicker";
  5. import {changeColor} from "../Helpers/lights";
  6. import BrightnessSlider from "./Misc/BrightnessSlider";
  7. function LGroup({id, name}) {
  8. const lights = useLights({groupId: id});
  9. const light = lights !== null && lights.length > 0 ? lights[0] : null;
  10. const [color, setColor] = useState(null);
  11. const [brightness, setBrightness] = useState(null);
  12. const [power, setPower] = useState(null);
  13. useEffect(() => {
  14. if (light !== null) {
  15. setColor(light.color);
  16. setBrightness(light.brightness);
  17. setPower(light.on);
  18. }
  19. }, [light]);
  20. if (light === null || color === null || brightness === null || power === null) {
  21. return <></>;
  22. }
  23. function recolor(newColor) {
  24. setColor(newColor);
  25. lights.forEach(l => changeColor(l.id, newColor, null, null));
  26. }
  27. function rebrightness(newBrightness) {
  28. setBrightness(newBrightness);
  29. lights.forEach(l => changeColor(l.id, null, newBrightness, null));
  30. }
  31. function repower(newPower) {
  32. setPower(newPower);
  33. lights.forEach(l => changeColor(l.id, null, null, newPower));
  34. }
  35. return (
  36. <Col lg={4} md={6} sm={12}>
  37. <Card className="mt-3">
  38. <CardHeader>
  39. {name}
  40. </CardHeader>
  41. <CardBody>
  42. <FormGroup>
  43. {power && <ColorPicker color={color} onChange={recolor}/>}
  44. </FormGroup>
  45. <FormGroup>
  46. {power && <BrightnessSlider brightness={brightness} onChange={rebrightness}/>}
  47. </FormGroup>
  48. <FormGroup className="on-switch">
  49. <CustomInput type="switch"
  50. id={`switch-power-${id}`}
  51. name="power"
  52. label={power ? "På" : "Av"}
  53. checked={power}
  54. onChange={e => repower(e.target.checked)}/>
  55. </FormGroup>
  56. </CardBody>
  57. </Card>
  58. </Col>
  59. );
  60. }
  61. export default LGroup;