chore: refactored code, added some functions
This commit is contained in:
42
app/components/WebConsole/serverControl.tsx
Normal file
42
app/components/WebConsole/serverControl.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import React from "react";
|
||||
|
||||
interface Props {
|
||||
websocketRef: React.MutableRefObject<WebSocket | null>;
|
||||
}
|
||||
|
||||
const serverControl = ({ websocketRef }: Props) => {
|
||||
const setStateFunction = (state: string) => {
|
||||
websocketRef.current?.send(`{"event":"set state","args":["${state}"]}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
onClick={() => {
|
||||
setStateFunction("start");
|
||||
}}
|
||||
className="btn btn-success"
|
||||
>
|
||||
Start
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
setStateFunction("restart");
|
||||
}}
|
||||
className="btn btn-warning"
|
||||
>
|
||||
Restart
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
setStateFunction("stop");
|
||||
}}
|
||||
className="btn btn-danger"
|
||||
>
|
||||
Stop
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default serverControl;
|
||||
Reference in New Issue
Block a user