mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-13 11:13:50 +01:00
Replace ConnectionBauble Class Component with Functional one
This commit is contained in:
parent
88d8f13847
commit
725fb05bb3
@ -1,41 +1,21 @@
|
|||||||
import React from "react";
|
import React, {useState, useEffect } from "react";
|
||||||
|
|
||||||
interface baubleState {
|
|
||||||
connection: boolean;
|
|
||||||
callback: () => boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface baubleProps {
|
interface baubleProps {
|
||||||
callback: () => boolean;
|
callback: () => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ConnectionBauble extends React.Component<baubleProps> {
|
export const ConnectionBauble = (props: baubleProps): React.ReactElement => {
|
||||||
timerID: NodeJS.Timer;
|
const [connection, setConnection] = useState(props.callback())
|
||||||
state: baubleState;
|
|
||||||
|
|
||||||
constructor(props: baubleProps) {
|
useEffect(() => {
|
||||||
super(props);
|
setInterval(() => {
|
||||||
this.state = {
|
setConnection(props.callback());
|
||||||
connection: props.callback(),
|
}, 1000);
|
||||||
callback: props.callback,
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount(): void {
|
return (
|
||||||
this.timerID = setInterval(() => this.tick(), 1000);
|
<div className="ConnectionBauble">
|
||||||
}
|
{connection? "Connected" : "Disconnected"}
|
||||||
|
</div>
|
||||||
componentWillUnmount(): void {
|
);
|
||||||
clearInterval(this.timerID);
|
|
||||||
}
|
|
||||||
|
|
||||||
tick(): void {
|
|
||||||
this.setState({
|
|
||||||
connection: this.state.callback(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render(): string {
|
|
||||||
return this.state.connection ? "Connected" : "Disconnected";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import { GameOptionsTab } from "../GameOptionsTab";
|
|||||||
import { GameOptionsPage } from "./GameOptionsPage";
|
import { GameOptionsPage } from "./GameOptionsPage";
|
||||||
import { OptionsSlider } from "./OptionsSlider";
|
import { OptionsSlider } from "./OptionsSlider";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import { ConnectionBauble } from "./ConnectionBauble";
|
import { ConnectionBaub, ConnectionBauble } from "./ConnectionBauble";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
currentTab: GameOptionsTab;
|
currentTab: GameOptionsTab;
|
||||||
|
Loading…
Reference in New Issue
Block a user