From f22f0ed50af846b3dfd989a1812df52b1f0eed60 Mon Sep 17 00:00:00 2001 From: SagePtr Date: Sat, 29 Jan 2022 20:02:07 +0200 Subject: [PATCH] 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.