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 tool to list of installed augmentations #1833

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
27 changes: 25 additions & 2 deletions src/Augmentation/ui/InstalledAugmentations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Box, ListItemButton, Paper, Typography } from "@mui/material";
import Button from "@mui/material/Button";
import List from "@mui/material/List";
import Tooltip from "@mui/material/Tooltip";
import TextField from "@mui/material/TextField";
import Search from "@mui/icons-material/Search";
import React, { useState } from "react";
import { OwnedAugmentationsOrderSetting } from "../../Settings/SettingEnums";
import { Settings } from "../../Settings/Settings";
Expand All @@ -23,8 +25,21 @@ export function InstalledAugmentations(): React.ReactElement {

const [selectedAug, setSelectedAug] = useState(sourceAugs[0]);

const [filterText, setFilterText] = useState("");
const matches = (s1: string, s2: string) => s1.toLowerCase().includes(s2.toLowerCase());
const filteredSourceAugs = sourceAugs.filter((aug) => {
if (filterText === "") {
return true;
}
return (
matches(Augmentations[aug.name].name, filterText) ||
matches(Augmentations[aug.name].info, filterText) ||
matches(Augmentations[aug.name].stats, filterText)
);
});

if (Settings.OwnedAugmentationsOrder === OwnedAugmentationsOrderSetting.Alphabetically) {
sourceAugs.sort((aug1, aug2) => {
filteredSourceAugs.sort((aug1, aug2) => {
return aug1.name.localeCompare(aug2.name);
});
}
Expand Down Expand Up @@ -59,8 +74,16 @@ export function InstalledAugmentations(): React.ReactElement {
{sourceAugs.length > 0 ? (
<Paper sx={{ display: "grid", gridTemplateColumns: "1fr 3fr" }}>
<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}` }}>
{sourceAugs.map((k, i) => (
{filteredSourceAugs.map((k, i) => (
<ListItemButton key={i + 1} onClick={() => setSelectedAug(k)} selected={selectedAug === k}>
<Typography>{k.name}</Typography>
</ListItemButton>
Expand Down
Loading