Skip to content

Commit

Permalink
Disable lock button when clicked
Browse files Browse the repository at this point in the history
See also: #13
  • Loading branch information
BECATRUE committed Dec 7, 2024
1 parent 04d3870 commit b68f3c1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion wlm-ui/src/MainPage/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IProps extends ChannelInfo {
const Channel = (props: IProps) => {
const [isInUseButtonEnabled, setIsInUseButtonEnabled] = useState<boolean>(true);
const [shouldUpdatePlot, setShouldUpdatePlot] = useState<boolean>(true);
const [isLockButtonEnabled, setIsLockButtonEnabled] = useState<boolean>(true);
const [exposure, setExposure] = useState<number>(0);
const [period, setPeriod] = useState<number>(0);
const measurementsRef = useRef(props.measurements);
Expand Down Expand Up @@ -117,6 +118,10 @@ const Channel = (props: IProps) => {
setIsInUseButtonEnabled(true);
}, [props.inUse]);

useEffect(() => {
setIsLockButtonEnabled(true);
}, [props.hasLock]);

return (
<div className='channel-item'>
<div className='channel-title'>
Expand Down Expand Up @@ -206,7 +211,15 @@ const Channel = (props: IProps) => {
<div className='channel-lock-container'>
<span>{props.lock.locked ? `Locked by ${props.lock.owner}` : 'Open'}</span>
<button
onClick={props.hasLock ? props.onClickReleaseLock : props.onClickTryLock }
disabled={!isLockButtonEnabled}
onClick={() => {
setIsLockButtonEnabled(false);
if (props.hasLock) {
props.onClickReleaseLock();
} else {
props.onClickTryLock();
}
}}
>
{props.hasLock ? 'Release' : 'Acquire'}
</button>
Expand Down

0 comments on commit b68f3c1

Please sign in to comment.