From dbd6c0226448cd84dffc8893a93371cbc81eeee7 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Wed, 23 Mar 2022 11:16:25 -0400 Subject: [PATCH] Fixup search Fix selecting cell 0, 0 and improve regex criteria for when cell results show vs mod results. --- components/SearchBar.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/SearchBar.tsx b/components/SearchBar.tsx index c18d220..32e358c 100644 --- a/components/SearchBar.tsx +++ b/components/SearchBar.tsx @@ -28,7 +28,7 @@ for (let x = -77; x < 76; x++) { const cellSearch = new MiniSearch({ fields: ["id"], storeFields: ["id", "name", "x", "y"], - tokenize: (s) => [s.replace(/cell\s?/gi, "")], + tokenize: (s) => [s.replace(/(cell\s?)|\s/gi, "")], searchOptions: { fields: ["id"], prefix: true, @@ -82,7 +82,13 @@ const SearchBar: React.FC = ({ counts, sidebarOpen }) => { onInputValueChange: ({ inputValue }) => { if (inputValue) { let results: SearchResult[] = []; - if (modSearch.current && !/^(cell)?\s?-?\d+,-?\d+$/i.test(inputValue)) { + if ( + modSearch.current && + !/(^cell\s?-?\d+\s?,?\s?-?\d*$)|(^-?\d+\s?,\s?-?\d*$)/i.test( + inputValue + ) + ) { + console.log("searching mods"); results = results.concat( modSearch.current.search(inputValue).sort((resultA, resultB) => { if (counts) { @@ -109,7 +115,7 @@ const SearchBar: React.FC = ({ counts, sidebarOpen }) => { onSelectedItemChange: ({ selectedItem }) => { if (selectedItem) { setSearchFocused(false); - if (selectedItem.x && selectedItem.y) { + if (selectedItem.x !== undefined && selectedItem.y !== undefined) { router.push({ query: { cell: `${selectedItem.x},${selectedItem.y}` }, });