From b844593e22f8b1c4b2ffa56a97ddd67f82ee7b49 Mon Sep 17 00:00:00 2001 From: Michael Ficocelli Date: Tue, 12 Sep 2023 01:36:47 -0400 Subject: [PATCH] UI: Add filter to faction augmentation purchase page (#783) --- src/Faction/ui/AugmentationsPage.tsx | 37 +++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Faction/ui/AugmentationsPage.tsx b/src/Faction/ui/AugmentationsPage.tsx index 5d141770b..c1b9c0c9f 100644 --- a/src/Faction/ui/AugmentationsPage.tsx +++ b/src/Faction/ui/AugmentationsPage.tsx @@ -1,5 +1,6 @@ -import React from "react"; -import { Box, Button, Tooltip, Typography, Paper, Container } from "@mui/material"; +import React, { useState, useMemo } from "react"; +import { Box, Button, Tooltip, Typography, Paper, Container, TextField } from "@mui/material"; +import SearchIcon from "@mui/icons-material/Search"; import { Augmentations } from "../../Augmentation/Augmentations"; import { getAugCost, getGenericAugmentationPriceMultiplier } from "../../Augmentation/AugmentationHelpers"; @@ -20,9 +21,24 @@ import { useRerender } from "../../ui/React/hooks"; /** Root React Component for displaying a faction's "Purchase Augmentations" page */ export function AugmentationsPage({ faction }: { faction: Faction }): React.ReactElement { const rerender = useRerender(400); + const [filterText, setFilterText] = useState(""); + + const matches = (s1: string, s2: string) => s1.toLowerCase().includes(s2.toLowerCase()); + const factionAugs = useMemo(() => getFactionAugmentationsFiltered(faction), [faction]); + const filteredFactionAugs = useMemo( + () => + factionAugs.filter( + (aug: AugmentationName) => + !filterText || + matches(Augmentations[aug].name, filterText) || + matches(Augmentations[aug].info, filterText) || + matches(Augmentations[aug].stats, filterText), + ), + [filterText, factionAugs], + ); function getAugs(): AugmentationName[] { - return getFactionAugmentationsFiltered(faction); + return filteredFactionAugs; } function getAugsSorted(): AugmentationName[] { @@ -113,6 +129,10 @@ export function AugmentationsPage({ faction }: { faction: Faction }): React.Reac rerender(); } + function handleFilterChange(event: React.ChangeEvent): void { + setFilterText(event.target.value); + } + const augs = getAugsSorted(); const purchasable = augs.filter( (aug: string) => @@ -202,6 +222,17 @@ export function AugmentationsPage({ faction }: { faction: Faction }): React.Reac Sort by Purchasable + , + spellCheck: false, + }} + sx={{ pt: 1 }} + />