Skip to content

Commit

Permalink
Merge pull request #4243 from seanquinn917/search-bar-2024-handle-key…
Browse files Browse the repository at this point in the history
…-press

Search bar 2024 handle key press
  • Loading branch information
DaleMcGrew authored Feb 5, 2025
2 parents 4c92d25 + 9dc0010 commit 51396a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/js/common/components/Challenge/ChallengesHomeFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function ChallengesHomeFilter (props) {
searchFunction={props.searchFunction}
clearFunction={props.clearSearchFunction}
searchUpdateDelayTime={500}
trackSearch={true}
parentComponentName="ChallengesHomeFilter"
/>
</SearchBarWrapper>
</ChallengesHomeFilterWrapper>
Expand Down
30 changes: 25 additions & 5 deletions src/js/common/components/Search/SearchBar2024.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import styled from 'styled-components';
import { blurTextFieldAndroid, focusTextFieldAndroid } from '../../utils/cordovaUtils';
import { renderLog } from '../../utils/logging';
import SearchBase from './SearchBase';
import VoterStore from '../../../stores/VoterStore';
import TagManager from 'react-gtm-module';

/* eslint-disable jsx-a11y/control-has-associated-label */
class SearchBar2024 extends Component {
Expand Down Expand Up @@ -56,12 +58,30 @@ class SearchBar2024 extends Component {
}
}

handleKeyPress () {
if (this.timer) clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.props.searchFunction(this.state.searchString);
}, this.props.searchUpdateDelayTime);

handleKeyPress = () => {
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
const { searchString } = this.state;
if (searchString.length === 0) {
return;
}
this.props.searchFunction(searchString);
if(this.props.trackSearch){
const dataLayerObject = {
event: 'KeyWord Search',
search_keyword: searchString,
voterWeVoteId: VoterStore.getVoterWeVoteId(),
};
console.log(dataLayerObject)
TagManager.dataLayer({dataLayer: dataLayerObject});
}
}, 3000);
const { searchString } = this.state;
this.props.searchFunction(searchString);
};

clearQuery () {
this.props.clearFunction();
Expand Down

0 comments on commit 51396a0

Please sign in to comment.