From 629c77c110042d5160f5218bee54f76b81c4dad2 Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Tue, 20 Apr 2021 03:37:05 -0400 Subject: Multiple state changes and efficiency fixes. --- react-frontend/src/components/HubSearch.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'react-frontend/src/components/HubSearch.js') diff --git a/react-frontend/src/components/HubSearch.js b/react-frontend/src/components/HubSearch.js index 2ae1a32..827ea6d 100644 --- a/react-frontend/src/components/HubSearch.js +++ b/react-frontend/src/components/HubSearch.js @@ -13,27 +13,32 @@ import Search from "./HubSearch.js"; * in a vertical layout. */ function HubSearch(props) { - const [queryString, setQueryString] = useState(""); + const [queryString, setQueryString] = useState("", (s) => s.toLowerCase()); const [displayedItems, setDisplayedItems] = useState([]); /** * Method that determines whehter the Hub should be showed. * @returns {Boolean} True if to be shown, false if not. */ - const toInclude = (holder) => { + const toInclude = holder => { // TODO: add number search or differentiate between it // TODO: add sus score range.... - const matchingId = queryString.toLowerCase().includes(holder?.id ?? ""); - const matchingName = queryString.toLowerCase().includes(holder?.name ?? ""); - return matchingId || matchingName; + if (!holder) { + return false; + }; + + // const matchingId = holder.id.toString().includes(queryString.toLowerCase()); + const matchingName = holder.name.toLowerCase().includes(queryString); + return matchingName; } /** * Filters the items to be shown, then created the iteams and sets the state with the items. */ const filterItems = () => { + console.log(queryString); const criteria = props.data.filter(holder => toInclude(holder)); - setDisplayedItems(criteria.map(hub => )) + setDisplayedItems(criteria.map(hub =>

{hub.name}

)) } /** @@ -49,7 +54,7 @@ function HubSearch(props) {

Search

- setQueryString(e.value)}> + setQueryString(e.target.value)}>
    {displayedItems}
;
-- cgit v1.2.3-70-g09d2