From e6fe0b282fe8e6fd79e8b6f7c94041d84a1a6a54 Mon Sep 17 00:00:00 2001 From: Zack Youngren Date: Wed, 17 Jul 2024 17:39:52 -0400 Subject: [PATCH] Search for each cross street of a dock independently (#34) --- app/DockData.tsx | 26 ++++++++++++++++++++++---- package-lock.json | 15 --------------- package.json | 1 - 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/DockData.tsx b/app/DockData.tsx index cc7b345..5ae6c18 100644 --- a/app/DockData.tsx +++ b/app/DockData.tsx @@ -5,7 +5,6 @@ import { Granularity } from './constants'; import LoadingSpinner from './LoadingSpinner'; import Topline from './Topline'; import match from 'autosuggest-highlight/match'; -import { matchSorter } from 'match-sorter'; import parse from 'autosuggest-highlight/parse'; import { Alert, @@ -171,9 +170,28 @@ export default memo(function DockData() { disabled={docksLoading} options={['', ...dockNames]} value={dock.name} - filterOptions={(options, { inputValue }) => - matchSorter(options, inputValue) - } + filterOptions={(stations, { inputValue }) => { + const inputTokens = inputValue + .split(' ') + .map((v) => v.trim().toLowerCase()) + .filter((t) => t !== '&'); + + return stations.filter((station) => { + const lowercaseStation = station.toLowerCase(); + + if (lowercaseStation.includes('&')) { + const [firstPart, secondPart] = lowercaseStation + .split('&') + .map((p) => p.trim()); + + return inputTokens.every( + (v) => firstPart.includes(v) || secondPart.includes(v), + ); + } else { + return inputTokens.every((v) => lowercaseStation.includes(v)); + } + }); + }} onChange={handleDockChange} renderInput={(p) => (