Skip to content

Commit

Permalink
Search for each cross street of a dock independently (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
zack authored Jul 17, 2024
1 parent 374ccf8 commit e6fe0b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
26 changes: 22 additions & 4 deletions app/DockData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => (
<TextField
Expand Down
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"concat-files": "^0.1.1",
"date-fns": "^3.6.0",
"immer": "^10.1.1",
"match-sorter": "^6.3.4",
"next": "^14.2.4",
"prisma-repl": "^1.4.0",
"react": "18.3.1",
Expand Down

0 comments on commit e6fe0b2

Please sign in to comment.