Skip to content

Commit

Permalink
UI: Add filter to faction augmentation purchase page (bitburner-offic…
Browse files Browse the repository at this point in the history
  • Loading branch information
ficocelliguy authored and G4mingJon4s committed Mar 23, 2024
1 parent 711624e commit ae17007
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/Faction/ui/AugmentationsPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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[] {
Expand Down Expand Up @@ -113,6 +129,10 @@ export function AugmentationsPage({ faction }: { faction: Faction }): React.Reac
rerender();
}

function handleFilterChange(event: React.ChangeEvent<HTMLInputElement>): void {
setFilterText(event.target.value);
}

const augs = getAugsSorted();
const purchasable = augs.filter(
(aug: string) =>
Expand Down Expand Up @@ -202,6 +222,17 @@ export function AugmentationsPage({ faction }: { faction: Faction }): React.Reac
Sort by Purchasable
</Button>
</Box>
<TextField
value={filterText}
onChange={handleFilterChange}
autoFocus
placeholder="Filter augmentations"
InputProps={{
startAdornment: <SearchIcon />,
spellCheck: false,
}}
sx={{ pt: 1 }}
/>
</Paper>
</Container>

Expand Down

0 comments on commit ae17007

Please sign in to comment.