Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Add filter to faction augmentation purchase page #783

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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