From 1c9542d10274e76d7b6d117cb9913b3cab39e442 Mon Sep 17 00:00:00 2001
From: Olivier Gagnon
Date: Tue, 7 Sep 2021 17:26:49 -0400
Subject: [PATCH] tech vendor buttons update better
---
src/Locations/ui/CoresButton.tsx | 8 ++------
src/Locations/ui/RamButton.tsx | 8 ++------
src/Locations/ui/TechVendorLocation.tsx | 12 ++++++++----
src/Locations/ui/TorButton.tsx | 8 ++------
4 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/src/Locations/ui/CoresButton.tsx b/src/Locations/ui/CoresButton.tsx
index 5eafd46a2..f66696d5a 100644
--- a/src/Locations/ui/CoresButton.tsx
+++ b/src/Locations/ui/CoresButton.tsx
@@ -9,14 +9,10 @@ import { MathComponent } from "mathjax-react";
type IProps = {
p: IPlayer;
+ rerender: () => void;
};
export function CoresButton(props: IProps): React.ReactElement {
- const setRerender = useState(false)[1];
- function rerender(): void {
- setRerender((old) => !old);
- }
-
const btnStyle = { display: "block" };
const homeComputer = props.p.getHomeComputer();
@@ -37,7 +33,7 @@ export function CoresButton(props: IProps): React.ReactElement {
if (!props.p.canAfford(cost)) return;
props.p.loseMoney(cost);
homeComputer.cpuCores++;
- rerender();
+ props.rerender();
}
return (
diff --git a/src/Locations/ui/RamButton.tsx b/src/Locations/ui/RamButton.tsx
index d98fabefe..fb63e8281 100644
--- a/src/Locations/ui/RamButton.tsx
+++ b/src/Locations/ui/RamButton.tsx
@@ -11,14 +11,10 @@ import { MathComponent } from "mathjax-react";
type IProps = {
p: IPlayer;
+ rerender: () => void;
};
export function RamButton(props: IProps): React.ReactElement {
- const setRerender = useState(false)[1];
- function rerender(): void {
- setRerender((old) => !old);
- }
-
const btnStyle = { display: "block" };
const homeComputer = props.p.getHomeComputer();
@@ -32,7 +28,7 @@ export function RamButton(props: IProps): React.ReactElement {
function buy(): void {
purchaseRamForHomeComputer(props.p);
- rerender();
+ props.rerender();
}
return (
diff --git a/src/Locations/ui/TechVendorLocation.tsx b/src/Locations/ui/TechVendorLocation.tsx
index abbaaa42b..e111a3fa7 100644
--- a/src/Locations/ui/TechVendorLocation.tsx
+++ b/src/Locations/ui/TechVendorLocation.tsx
@@ -3,7 +3,7 @@
*
* This subcomponent renders all of the buttons for purchasing things from tech vendors
*/
-import * as React from "react";
+import React, { useState } from "react";
import { Location } from "../Location";
import { createPurchaseServerPopup } from "../LocationsHelpers";
@@ -23,6 +23,10 @@ type IProps = {
};
export function TechVendorLocation(props: IProps): React.ReactElement {
+ const setRerender = useState(false)[1];
+ function rerender() {
+ setRerender((old) => !old);
+ }
const btnStyle = { display: "block" };
const purchaseServerButtons: React.ReactNode[] = [];
@@ -58,9 +62,9 @@ export function TechVendorLocation(props: IProps): React.ReactElement {
-
-
-
+
+
+
);
}
diff --git a/src/Locations/ui/TorButton.tsx b/src/Locations/ui/TorButton.tsx
index a77faf61b..b4673cfd5 100644
--- a/src/Locations/ui/TorButton.tsx
+++ b/src/Locations/ui/TorButton.tsx
@@ -11,19 +11,15 @@ import { Money } from "../../ui/React/Money";
type IProps = {
p: IPlayer;
+ rerender: () => void;
};
export function TorButton(props: IProps): React.ReactElement {
- const setRerender = useState(false)[1];
- function rerender(): void {
- setRerender((old) => !old);
- }
-
const btnStyle = { display: "block" };
function buy(): void {
purchaseTorRouter(props.p);
- rerender();
+ props.rerender();
}
if (props.p.hasTorRouter()) {