mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-29 19:13:49 +01:00
few fixes in the purchase server popup
This commit is contained in:
parent
bc33f67409
commit
99e82cd867
@ -1,46 +1,40 @@
|
|||||||
/**
|
/**
|
||||||
* React Component for the popup used to purchase a new server.
|
* React Component for the popup used to purchase a new server.
|
||||||
*/
|
*/
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { removePopup } from "../../ui/React/createPopup";
|
import { removePopup } from "../../ui/React/createPopup";
|
||||||
import { purchaseServer } from "../../Server/ServerPurchases";
|
import { purchaseServer } from "../../Server/ServerPurchases";
|
||||||
import { numeralWrapper } from "../../ui/numeralFormat";
|
import { numeralWrapper } from "../../ui/numeralFormat";
|
||||||
import { Money } from "../../ui/React/Money";
|
import { Money } from "../../ui/React/Money";
|
||||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||||
import { StdButton } from "../../ui/React/StdButton";
|
import { StdButton } from "../../ui/React/StdButton";
|
||||||
|
|
||||||
interface IPurchaseServerPopupProps {
|
|
||||||
ram: number;
|
|
||||||
cost: number;
|
|
||||||
p: IPlayer;
|
|
||||||
popupId: string;
|
|
||||||
rerender: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function PurchaseServerPopup(props: IPurchaseServerPopupProps): React.ReactElement {
|
|
||||||
const [hostname, setHostname] = useState("");
|
|
||||||
|
|
||||||
function tryToPurchaseServer(): void {
|
|
||||||
purchaseServer(hostname, props.ram, props.cost, props.p);
|
|
||||||
|
|
||||||
removePopup(props.popupId);
|
interface IPurchaseServerPopupProps {
|
||||||
}
|
ram: number;
|
||||||
|
cost: number;
|
||||||
function cancel(): void {
|
p: IPlayer;
|
||||||
removePopup(props.popupId);
|
popupId: string;
|
||||||
}
|
rerender: () => void;
|
||||||
|
}
|
||||||
function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void {
|
|
||||||
if (event.keyCode === 13) tryToPurchaseServer();
|
export function PurchaseServerPopup(props: IPurchaseServerPopupProps): React.ReactElement {
|
||||||
if (event.keyCode === 27) cancel();
|
const [hostname, setHostname] = useState("");
|
||||||
}
|
|
||||||
|
function tryToPurchaseServer(): void {
|
||||||
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
|
purchaseServer(hostname, props.ram, props.cost, props.p);
|
||||||
setHostname(event.target.value);
|
|
||||||
props.rerender();
|
removePopup(props.popupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
function onKeyUp(event: React.KeyboardEvent<HTMLInputElement>): void {
|
||||||
|
if (event.keyCode === 13) tryToPurchaseServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
|
||||||
|
setHostname(event.target.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
<>
|
<>
|
||||||
Would you like to purchase a new server with {numeralWrapper.formatRAM(props.ram)} of RAM for{" "}
|
Would you like to purchase a new server with {numeralWrapper.formatRAM(props.ram)} of RAM for{" "}
|
||||||
<Money money={props.cost} player={props.p} />?
|
<Money money={props.cost} player={props.p} />?
|
||||||
@ -50,20 +44,15 @@
|
|||||||
<br />
|
<br />
|
||||||
<div className="popup-box-input-div">
|
<div className="popup-box-input-div">
|
||||||
<input
|
<input
|
||||||
autoFocus
|
autoFocus
|
||||||
onKeyUp={onKeyUp}
|
onKeyUp={onKeyUp}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
className="text-input noselect"
|
className="text-input noselect"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Unique Hostname"
|
placeholder="Unique Hostname"
|
||||||
/>
|
|
||||||
<StdButton
|
|
||||||
onClick={tryToPurchaseServer}
|
|
||||||
text="Purchase Server"
|
|
||||||
disabled={!props.p.canAfford(props.cost)}
|
|
||||||
/>
|
/>
|
||||||
|
<StdButton onClick={tryToPurchaseServer} text="Purchase Server" disabled={!props.p.canAfford(props.cost)} />
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user