From 969f3170f1c6aeb3d1b5eace13d329c1a02b16e8 Mon Sep 17 00:00:00 2001 From: Aleksei Bezrodnov Date: Mon, 12 Jun 2023 07:04:56 +0200 Subject: [PATCH] fix WorkInProgress component warnings (#600) Also improves WorkInProgress performance by reducing unnecessary rerenders --- src/ui/WorkInProgressRoot.tsx | 125 ++++++++++++++++------------------ 1 file changed, 60 insertions(+), 65 deletions(-) diff --git a/src/ui/WorkInProgressRoot.tsx b/src/ui/WorkInProgressRoot.tsx index 3e009726e..7f64832b1 100644 --- a/src/ui/WorkInProgressRoot.tsx +++ b/src/ui/WorkInProgressRoot.tsx @@ -1,24 +1,27 @@ -import { Box, Container, Paper, Table, TableBody, Tooltip } from "@mui/material"; +import React from "react"; + +import { Box, Container, Paper, Table, TableBody, TableRow, TableCell, Tooltip } from "@mui/material"; import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; -import { uniqueId } from "lodash"; -import React from "react"; -import { Companies } from "../Company/Companies"; -import { CONSTANTS } from "../Constants"; -import { FactionWorkType, LocationName } from "@enums"; -import { Locations } from "../Locations/Locations"; -import { Settings } from "../Settings/Settings"; -import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions"; + import { Player } from "@player"; -import { Router } from "./GameRoot"; -import { Page } from "./Router"; -import { formatExp, formatPercent } from "./formatNumber"; +import { FactionWorkType, LocationName } from "@enums"; + import { Money } from "./React/Money"; import { MoneyRate } from "./React/MoneyRate"; import { ProgressBar } from "./React/Progress"; import { Reputation } from "./React/Reputation"; import { ReputationRate } from "./React/ReputationRate"; import { StatsRow } from "./React/StatsRow"; +import { useRerender } from "./React/hooks"; + +import { Companies } from "../Company/Companies"; +import { CONSTANTS } from "../Constants"; +import { Locations } from "../Locations/Locations"; +import { Settings } from "../Settings/Settings"; +import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions"; +import { filterTruthy } from "../utils/helpers/ArrayHelpers"; + import { isCrimeWork } from "../Work/CrimeWork"; import { isClassWork } from "../Work/ClassWork"; import { WorkStats } from "../Work/WorkStats"; @@ -26,7 +29,9 @@ import { isCreateProgramWork } from "../Work/CreateProgramWork"; import { isGraftingWork } from "../Work/GraftingWork"; import { isFactionWork } from "../Work/FactionWork"; import { isCompanyWork } from "../Work/CompanyWork"; -import { useRerender } from "./React/hooks"; +import { Router } from "./GameRoot"; +import { Page } from "./Router"; +import { formatExp, formatPercent } from "./formatNumber"; const CYCLES_PER_SEC = 1000 / CONSTANTS.MilliPerCycle; @@ -38,7 +43,7 @@ interface IWorkInfo { title: string | React.ReactElement; description?: string | React.ReactElement; - gains?: (string | React.ReactElement)[]; + gains?: React.ReactElement[]; progress?: { elapsed?: number; remaining?: number; @@ -50,146 +55,134 @@ interface IWorkInfo { } function ExpRows(rate: WorkStats): React.ReactElement[] { - return [ - rate.hackExp > 0 ? ( + return filterTruthy([ + rate.hackExp > 0 && ( - ) : ( - <> ), - rate.strExp > 0 ? ( + rate.strExp > 0 && ( - ) : ( - <> ), - rate.defExp > 0 ? ( + rate.defExp > 0 && ( - ) : ( - <> ), - rate.dexExp > 0 ? ( + rate.dexExp > 0 && ( - ) : ( - <> ), - rate.agiExp > 0 ? ( + rate.agiExp > 0 && ( - ) : ( - <> ), - rate.chaExp > 0 ? ( + rate.chaExp > 0 && ( - ) : ( - <> ), - ]; + ]); } /* Because crime exp is given all at once at the end, we don't care about the cycles per second. */ function CrimeExpRows(rate: WorkStats): React.ReactElement[] { - return [ - rate.hackExp > 0 ? ( + return filterTruthy([ + rate.hackExp > 0 && ( - ) : ( - <> ), - rate.strExp > 0 ? ( + rate.strExp > 0 && ( - ) : ( - <> ), - rate.defExp > 0 ? ( + rate.defExp > 0 && ( - ) : ( - <> ), - rate.dexExp > 0 ? ( + rate.dexExp > 0 && ( - ) : ( - <> ), - rate.agiExp > 0 ? ( + rate.agiExp > 0 && ( - ) : ( - <> ), - rate.chaExp > 0 ? ( + rate.chaExp > 0 && ( - ) : ( - <> ), - ]; + ]); } export function WorkInProgressRoot(): React.ReactElement { @@ -227,9 +220,15 @@ export function WorkInProgressRoot(): React.ReactElement { title: `You are attempting ${crime.workName}`, gains: [ - Success chance: {formatPercent(successChance)}, - Gains (on success), - + + + Success chance: ${formatPercent(successChance)} + + + Gains (on success) + + , + @@ -274,7 +273,7 @@ export function WorkInProgressRoot(): React.ReactElement { ), gains: [ - + () @@ -451,12 +450,12 @@ export function WorkInProgressRoot(): React.ReactElement { ), gains: [ - + , - + @@ -492,11 +491,7 @@ export function WorkInProgressRoot(): React.ReactElement { {workInfo.description} {workInfo.gains && ( - - {workInfo.gains.map((row) => ( - {row} - ))} - + {workInfo.gains}
)}