From 60ec1569f0b3ff2d62ef57c2de3fe15e95136399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 2 Aug 2023 12:06:19 +0200 Subject: [PATCH] frontend: updating button component --- .../{button.tsx => ButtonComponent.tsx} | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) rename frontend/src/components/{button.tsx => ButtonComponent.tsx} (67%) diff --git a/frontend/src/components/button.tsx b/frontend/src/components/ButtonComponent.tsx similarity index 67% rename from frontend/src/components/button.tsx rename to frontend/src/components/ButtonComponent.tsx index a817536..e4054e9 100644 --- a/frontend/src/components/button.tsx +++ b/frontend/src/components/ButtonComponent.tsx @@ -1,41 +1,45 @@ -import React, { MouseEventHandler, useEffect, useRef, useState } from 'react'; -import { OverlayTrigger, Badge, Button, Tooltip, ToggleButton } from 'react-bootstrap'; +import React, { useEffect, useRef } from 'react'; +import { OverlayTrigger, Badge, Tooltip, ToggleButton } from 'react-bootstrap'; +import { socket } from '../socket'; interface ButtonComponentProps { name: string; - fullname?: string; + parent_path?: string; value: boolean; readOnly: boolean; docString: string; - onToggle?: MouseEventHandler; mapping?: [string, string]; // Enforce a tuple of two strings } export const ButtonComponent = React.memo((props: ButtonComponentProps) => { const renderCount = useRef(0); - const [checked, setChecked] = useState(false); - useEffect(() => { renderCount.current++; }); - const { name, fullname, value, readOnly, docString, onToggle, mapping } = props; + const { name, parent_path: fullname, value, readOnly, docString, mapping } = props; const buttonName = mapping ? (value ? mapping[0] : mapping[1]) : name; const tooltip = {docString}; + const setChecked = (checked: boolean) => { + socket.emit('frontend_update', { + name: name, + fullname: fullname, + value: checked + }); + }; + return (

Render count: {renderCount.current}

setChecked(e.currentTarget.checked)}>

{buttonName}