UI: Allow filtering graftable augmentations (#1570)

This commit is contained in:
catloversg 2024-08-15 12:18:27 +07:00 committed by GitHub
parent dbeaef94a2
commit 440c074606
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,8 +4,8 @@ import { Player } from "@player";
import { AugmentationName } from "@enums";
import React, { useState } from "react";
import { CheckBox, CheckBoxOutlineBlank, Construction } from "@mui/icons-material";
import { Box, Button, Container, List, ListItemButton, Paper, Typography } from "@mui/material";
import { CheckBox, CheckBoxOutlineBlank, Construction, Search } from "@mui/icons-material";
import { Box, Button, Container, List, ListItemButton, Paper, TextField, Typography } from "@mui/material";
import { GraftingWork } from "../../../Work/GraftingWork";
import { Augmentations } from "../../../Augmentation/Augmentations";
@ -66,17 +66,25 @@ export const GraftingRoot = (): React.ReactElement => {
const [selectedAug, setSelectedAug] = useState(getGraftingAvailableAugs()[0]);
const [graftOpen, setGraftOpen] = useState(false);
const [filterText, setFilterText] = useState("");
const selectedAugmentation = Augmentations[selectedAug];
const rerender = useCycleRerender();
const matches = (s1: string, s2: string) => s1.toLowerCase().includes(s2.toLowerCase());
const getAugsSorted = (): AugmentationName[] => {
const augs = getGraftingAvailableAugs();
switch (Settings.PurchaseAugmentationsOrder) {
case PurchaseAugmentationsOrderSetting.Cost:
return augs.sort((a, b) => graftableAugmentations[a].cost - graftableAugmentations[b].cost);
default:
return augs;
if (Settings.PurchaseAugmentationsOrder === PurchaseAugmentationsOrderSetting.Cost) {
augs.sort((a, b) => graftableAugmentations[a].cost - graftableAugmentations[b].cost);
}
if (filterText !== "") {
return augs.filter(
(aug: AugmentationName) =>
matches(Augmentations[aug].name, filterText) ||
matches(Augmentations[aug].info, filterText) ||
matches(Augmentations[aug].stats, filterText),
);
}
return augs;
};
const switchSortOrder = (newOrder: PurchaseAugmentationsOrderSetting): void => {
@ -114,19 +122,29 @@ export const GraftingRoot = (): React.ReactElement => {
</Paper>
{getGraftingAvailableAugs().length > 0 ? (
<Paper sx={{ mb: 1, width: "fit-content", display: "grid", gridTemplateColumns: "1fr 3fr" }}>
<List sx={{ height: 400, overflowY: "scroll", borderRight: `1px solid ${Settings.theme.welllight}` }}>
{getAugsSorted().map((k, i) => (
<ListItemButton key={i + 1} onClick={() => setSelectedAug(k)} selected={selectedAug === k}>
<Typography
sx={{
color: canGraft(graftableAugmentations[k]) ? Settings.theme.primary : Settings.theme.disabled,
}}
>
{k}
</Typography>
</ListItemButton>
))}
</List>
<Box>
<TextField
style={{ width: "100%" }}
value={filterText}
onChange={(e) => {
setFilterText(e.target.value);
}}
InputProps={{ startAdornment: <Search /> }}
/>
<List sx={{ height: 400, overflowY: "scroll", borderRight: `1px solid ${Settings.theme.welllight}` }}>
{getAugsSorted().map((k, i) => (
<ListItemButton key={i + 1} onClick={() => setSelectedAug(k)} selected={selectedAug === k}>
<Typography
sx={{
color: canGraft(graftableAugmentations[k]) ? Settings.theme.primary : Settings.theme.disabled,
}}
>
{k}
</Typography>
</ListItemButton>
))}
</List>
</Box>
<Box sx={{ m: 1 }}>
<Typography variant="h6" sx={{ display: "flex", alignItems: "center", flexWrap: "wrap" }}>
<Construction sx={{ mr: 1 }} /> {selectedAug}