From 66a593e06bf9d12cc91648fa2e246cc3afdc4778 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Mon, 6 Sep 2021 15:53:31 -0400 Subject: [PATCH] expand new city and new industry dont appear if you cant --- src/Corporation/ui/CityTabs.tsx | 54 ++++++++++++++++++++++--------- src/Corporation/ui/HeaderTabs.tsx | 51 +++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/src/Corporation/ui/CityTabs.tsx b/src/Corporation/ui/CityTabs.tsx index 03684af8c..2fbcf3574 100644 --- a/src/Corporation/ui/CityTabs.tsx +++ b/src/Corporation/ui/CityTabs.tsx @@ -10,6 +10,38 @@ import { OfficeSpace } from "../OfficeSpace"; import { Industry } from "./Industry"; import { IPlayer } from "../../PersonObjects/IPlayer"; +interface IExpandButtonProps { + corp: ICorporation; + division: IIndustry; + setCity: (name: string) => void; +} + +function ExpandButton(props: IExpandButtonProps) { + function openExpandNewCityModal(): void { + const popupId = "cmpy-mgmt-expand-city-popup"; + createPopup(popupId, ExpandNewCityPopup, { + popupId: popupId, + corp: props.corp, + division: props.division, + cityStateSetter: props.setCity, + }); + } + + const possibleCities = Object.keys(props.division.offices).filter( + (cityName: string) => props.division.offices[cityName] === 0, + ); + if (possibleCities.length === 0) return <>; + + return ( + + ); +} + interface IProps { city: string; division: IIndustry; @@ -20,16 +52,6 @@ interface IProps { export function CityTabs(props: IProps): React.ReactElement { const [city, setCity] = useState(props.city); - function openExpandNewCityModal(): void { - const popupId = "cmpy-mgmt-expand-city-popup"; - createPopup(popupId, ExpandNewCityPopup, { - popupId: popupId, - corp: props.corp, - division: props.division, - cityStateSetter: setCity, - }); - } - const office = props.division.offices[city]; if (office === 0) { setCity("Sector-12"); @@ -39,7 +61,8 @@ export function CityTabs(props: IProps): React.ReactElement { return ( <> {Object.values(props.division.offices).map( - (office: OfficeSpace | 0) => office !== 0 && ( + (office: OfficeSpace | 0) => + office !== 0 && ( ), )} - void; +} + +function ExpandButton(props: IExpandButtonProps): React.ReactElement { + const allIndustries = Object.keys(Industries).sort(); + const possibleIndustries = allIndustries + .filter( + (industryType: string) => + props.corp.divisions.find( + (division: IIndustry) => division.type === industryType, + ) === undefined, + ) + .sort(); + if (possibleIndustries.length === 0) return <>; + + function openNewIndustryPopup(): void { + const popupId = "cmpy-mgmt-expand-industry-popup"; + createPopup(popupId, NewIndustryPopup, { + corp: props.corp, + setDivisionName: props.setDivisionName, + popupId: popupId, + }); + } + + return ( + + ); +} interface IProps { corp: ICorporation; @@ -18,15 +54,6 @@ interface IProps { export function HeaderTabs(props: IProps): React.ReactElement { const [divisionName, setDivisionName] = useState("Overview"); - function openNewIndustryPopup(): void { - const popupId = "cmpy-mgmt-expand-industry-popup"; - createPopup(popupId, NewIndustryPopup, { - corp: props.corp, - setDivisionName: setDivisionName, - popupId: popupId, - }); - } - return ( <>
@@ -44,11 +71,7 @@ export function HeaderTabs(props: IProps): React.ReactElement { text={division.name} /> ))} - +