From a5f82e96ed733a9840b57d6009feca2b1b114f08 Mon Sep 17 00:00:00 2001 From: SagePtr Date: Sat, 29 Jan 2022 18:58:21 +0200 Subject: [PATCH 1/2] Don't hide irrelevant materials if their stock is not empty --- src/Corporation/ui/IndustryWarehouse.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Corporation/ui/IndustryWarehouse.tsx b/src/Corporation/ui/IndustryWarehouse.tsx index 4707afdef..94f46027f 100644 --- a/src/Corporation/ui/IndustryWarehouse.tsx +++ b/src/Corporation/ui/IndustryWarehouse.tsx @@ -83,8 +83,10 @@ function WarehouseRoot(props: IProps): React.ReactElement { const mats = []; for (const matName of Object.keys(props.warehouse.materials)) { if (!(props.warehouse.materials[matName] instanceof Material)) continue; - // Only create UI for materials that are relevant for the industry - if (!isRelevantMaterial(matName, division)) continue; + // Only create UI for materials that are relevant for the industry or in stock + const isInStock = props.warehouse.materials[matName].qty > 0; + const isRelevant = isRelevantMaterial(matName, division); + if (!isInStock && !isRelevant) continue; mats.push( Date: Sat, 29 Jan 2022 20:02:07 +0200 Subject: [PATCH 2/2] Hide irrelevant divisions in Export modal --- src/Corporation/ui/ExportModal.tsx | 21 +++++++++++++-------- src/Corporation/ui/Helpers.tsx | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Corporation/ui/ExportModal.tsx b/src/Corporation/ui/ExportModal.tsx index 54460583c..1d4405ffb 100644 --- a/src/Corporation/ui/ExportModal.tsx +++ b/src/Corporation/ui/ExportModal.tsx @@ -6,6 +6,7 @@ import { IIndustry } from "../IIndustry"; import { ExportMaterial } from "../Actions"; import { Modal } from "../../ui/React/Modal"; import { useCorporation } from "./Context"; +import { isRelevantMaterial } from "./Helpers"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; @@ -22,11 +23,13 @@ interface IProps { // Create a popup that lets the player manage exports export function ExportModal(props: IProps): React.ReactElement { const corp = useCorporation(); - if (corp.divisions.length === 0) throw new Error("Export popup created with no divisions."); - if (Object.keys(corp.divisions[0].warehouses).length === 0) + const possibleDivisions = corp.divisions.filter((division: IIndustry) => isRelevantMaterial(props.mat.name, division)); + if (possibleDivisions.length === 0) throw new Error("Export popup created with no divisions."); + const defaultDivision = possibleDivisions[0]; + if (Object.keys(defaultDivision.warehouses).length === 0) throw new Error("Export popup created in a division with no warehouses."); - const [industry, setIndustry] = useState(corp.divisions[0].name); - const [city, setCity] = useState(Object.keys(corp.divisions[0].warehouses)[0]); + const [industry, setIndustry] = useState(defaultDivision.name); + const [city, setCity] = useState(Object.keys(defaultDivision.warehouses)[0]); const [amt, setAmt] = useState(""); const setRerender = useState(false)[1]; @@ -84,10 +87,12 @@ export function ExportModal(props: IProps): React.ReactElement { second. You can set the export amount to 'MAX' to export all of the materials in this warehouse.