Skip to content

Commit

Permalink
chore: add isNullOrUndefined helper function and use it inside clear …
Browse files Browse the repository at this point in the history
…Input field
  • Loading branch information
matbmapspeople committed Jun 12, 2024
1 parent ef6efb7 commit 5654e16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/map-template/src/components/Search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ReactComponent as Legend } from '../../assets/legend.svg';
import isLegendDialogVisibleState from '../../atoms/isLegendDialogVisibleState';
import legendSortedFieldsSelector from '../../selectors/legendSortedFieldsSelector';
import searchAllVenuesState from '../../atoms/searchAllVenues';
import isNullOrUndefined from '../../helpers/isNullOrUndefined';

/**
* Show the search results.
Expand Down Expand Up @@ -99,7 +100,7 @@ function Search({ onSetSize, isOpen }) {
const searchAllVenues = useRecoilValue(searchAllVenuesState);

/**
*
*
* Get the locations and filter through them based on categories selected.
*
* @param {string} category
Expand Down Expand Up @@ -145,8 +146,8 @@ function Search({ onSetSize, isOpen }) {

setFilteredLocations([]);

// If keyboard is not null, clear the input field
if (keyboardRef.current !== null) {
// If keyboard is not null or undefined, clear the input field
if (!isNullOrUndefined(keyboardRef.current)) {
keyboardRef.current.clearInputField();
}
}
Expand Down Expand Up @@ -331,7 +332,7 @@ function Search({ onSetSize, isOpen }) {
}, [useKeyboard]);

/*
* React on changes in the selected category state.
* React on changes in the selected category state.
* If the selected category is present, get the filtered locations based on the selected category.
*/
useEffect(() => {
Expand All @@ -341,7 +342,7 @@ function Search({ onSetSize, isOpen }) {
}, [selectedCategory]);

/*
* Get the legend sections and determine
* Get the legend sections and determine
* If the legend button should be shown.
*/
useEffect(() => {
Expand Down
9 changes: 9 additions & 0 deletions packages/map-template/src/helpers/isNullOrUndefined.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Checks if the passed value is null or undefined.
*
* @param {any} value
* @returns {boolean}
*/
export default function isNullOrUndefined(value) {
return value === null || value === undefined;
}

0 comments on commit 5654e16

Please sign in to comment.