From 99e82cd867c1a32d6c81bb80d23499824a50f1b3 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sat, 11 Sep 2021 02:16:14 -0400 Subject: [PATCH] few fixes in the purchase server popup --- src/Locations/ui/PurchaseServerPopup.tsx | 95 +++++++++++------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/src/Locations/ui/PurchaseServerPopup.tsx b/src/Locations/ui/PurchaseServerPopup.tsx index 3e34d83a4..607d04ce1 100644 --- a/src/Locations/ui/PurchaseServerPopup.tsx +++ b/src/Locations/ui/PurchaseServerPopup.tsx @@ -1,46 +1,40 @@ /** * React Component for the popup used to purchase a new server. */ - import React, { useState } from "react"; - import { removePopup } from "../../ui/React/createPopup"; - import { purchaseServer } from "../../Server/ServerPurchases"; - import { numeralWrapper } from "../../ui/numeralFormat"; - import { Money } from "../../ui/React/Money"; - import { IPlayer } from "../../PersonObjects/IPlayer"; - 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); +import React, { useState } from "react"; +import { removePopup } from "../../ui/React/createPopup"; +import { purchaseServer } from "../../Server/ServerPurchases"; +import { numeralWrapper } from "../../ui/numeralFormat"; +import { Money } from "../../ui/React/Money"; +import { IPlayer } from "../../PersonObjects/IPlayer"; +import { StdButton } from "../../ui/React/StdButton"; - removePopup(props.popupId); - } - - function cancel(): void { - removePopup(props.popupId); - } - - function onKeyUp(event: React.KeyboardEvent): void { - if (event.keyCode === 13) tryToPurchaseServer(); - if (event.keyCode === 27) cancel(); - } - - function onChange(event: React.ChangeEvent): void { - setHostname(event.target.value); - props.rerender(); - } - - return ( +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); + } + + function onKeyUp(event: React.KeyboardEvent): void { + if (event.keyCode === 13) tryToPurchaseServer(); + } + + function onChange(event: React.ChangeEvent): void { + setHostname(event.target.value); + } + + return ( <> Would you like to purchase a new server with {numeralWrapper.formatRAM(props.ram)} of RAM for{" "} ? @@ -50,20 +44,15 @@
- +
- ); - } - \ No newline at end of file + ); +}