Skip to content

Commit

Permalink
keep SearchBar on previous places and add SearchBar2024 to Campaings …
Browse files Browse the repository at this point in the history
…and OneValue
  • Loading branch information
Ivan Kordonets committed Jan 31, 2024
1 parent c536db8 commit 6898daa
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/js/components/Ballot/BallotSearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import OrganizationActions from '../../actions/OrganizationActions';
import BallotStore from '../../stores/BallotStore';
import normalizedImagePath from '../../common/utils/normalizedImagePath';
import { renderLog } from '../../common/utils/logging';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import BallotItemSearchResult from './BallotItemSearchResult';

const thumbUpIcon = '../../../img/global/svg-icons/thumbs-up-icon.svg';
Expand Down Expand Up @@ -150,7 +150,7 @@ export default class BallotSearchResults extends Component {
<div>
{featureTurnedOff ? null : (
<div className="u-padding-bottom--sm">
<SearchBar2024
<SearchBar
clearButton
clearFunction={this.clearFunction}
clearSearchTextNow={clearSearchTextNow}
Expand Down
11 changes: 1 addition & 10 deletions src/js/components/CampaignsHome/CampaignsHomeFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@ import PropTypes from 'prop-types';
import React from 'react';
import styled from 'styled-components';
import { renderLog } from '../../common/utils/logging';
import { SearchTitleTop } from '../../common/components/Style/FilterStyles';
import StateDropDownCore from '../Filter/StateDropDownCore';
import SearchBar2024 from '../Search/SearchBar2024';

// React functional component example
function CampaignsHomeFilter (props) {
renderLog('CampaignsHomeFilter functional component');
const { classes, isSearching, listModeFiltersAvailable, searchText, stateCode } = props;
const { classes, listModeFiltersAvailable, stateCode } = props;
// console.log('CampaignsHomeFilter props.listModeFiltersAvailable:', props.listModeFiltersAvailable);
return (
<CampaignsHomeFilterWrapper>
{/* {(isSearching && searchText) && (
<SearchTitleTop>
Searching for &quot;
{searchText}
&quot;
</SearchTitleTop>
)} */}
{!!(listModeFiltersAvailable) && (
<CampaignsHomeFilterChoices>
{listModeFiltersAvailable.map((oneFilter) => (
Expand Down
9 changes: 7 additions & 2 deletions src/js/components/CandidateListRoot/CandidateListRoot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class CandidateListRoot extends Component {
}

componentDidMount () {
// console.log('CandidateListRoot componentDidMount');
this.candidateStoreListener = CandidateStore.addListener(this.onCandidateStoreChange.bind(this));
const { incomingList } = this.props;
// console.log('CandidateListRoot componentDidMount incomingList:', incomingList);
Expand Down Expand Up @@ -158,7 +157,6 @@ class CandidateListRoot extends Component {
orderByUltimateElectionDate = (firstEntry, secondEntry) => secondEntry.candidate_ultimate_election_date - firstEntry.candidate_ultimate_election_date;

onFilterOrListChange = () => {
// console.log('onFilterOrListChange');
// Start over with full list, and apply all active filters
const { listModeFilters, searchText, stateCode } = this.props;
const { candidateList } = this.state;
Expand Down Expand Up @@ -257,6 +255,7 @@ class CandidateListRoot extends Component {
filteredList = filteredList.sort(this.orderByUltimateElectionDate);
let searchResults = [];
let hideDisplayBecauseNoSearchResults = false;
this.callbackToParentHideIfNoResults(false);
if (searchText && searchText.length > 0) {
const searchTextLowercase = searchText.toLowerCase();
// console.log('searchTextLowercase:', searchTextLowercase);
Expand Down Expand Up @@ -289,6 +288,7 @@ class CandidateListRoot extends Component {
});
if (searchResults.length === 0) {
hideDisplayBecauseNoSearchResults = true;
this.callbackToParentHideIfNoResults(true);
}
if (searchResults.length > 0) {
// Only allow the first politician entry to be displayed (when there are multiple candidate entries for the same politician)
Expand Down Expand Up @@ -351,6 +351,10 @@ class CandidateListRoot extends Component {
});
}

callbackToParentHideIfNoResults = (newValue) => {
this.props.onHideIfNoResultsChange(newValue);
}

render () {
renderLog('CandidateListRoot'); // Set LOG_RENDER_EVENTS to log all renders
const { classes, hideIfNoResults, hideTitle, searchText, titleTextForList } = this.props;
Expand Down Expand Up @@ -435,6 +439,7 @@ class CandidateListRoot extends Component {
CandidateListRoot.propTypes = {
classes: PropTypes.object,
hideIfNoResults: PropTypes.bool,
onHideIfNoResultsChange: PropTypes.func,
hideTitle: PropTypes.bool,
incomingList: PropTypes.array,
incomingListTimeStampOfChange: PropTypes.number,
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/Friends/AskFriendsModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import withStyles from '@mui/styles/withStyles';
import withTheme from '@mui/styles/withTheme';
import PropTypes from 'prop-types';
import React, { Component, Suspense } from 'react';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import FriendList from './FriendList';
import FriendActions from '../../actions/FriendActions';
import apiCalming from '../../common/utils/apiCalming';
Expand Down Expand Up @@ -226,7 +226,7 @@ class AskFriendsModal extends Component {
<div className="full-width">
{totalCurrentFriendListCount > 10 && (
<>
<SearchBar2024
<SearchBar
clearButton
searchButton
placeholder="Search by name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { renderLog } from '../../common/utils/logging';
import BallotStore from '../../stores/BallotStore';
import FriendStore from '../../stores/FriendStore';
import sortFriendListByMutualFriends from '../../utils/friendFunctions';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import FriendList from './FriendList';

const SuggestedContacts = React.lazy(() => import(/* webpackChunkName: 'SuggestedContacts' */ './SuggestedContacts'));
Expand Down Expand Up @@ -175,7 +175,7 @@ class ShareWithFriendsModalBodyWithController extends Component {
<div className="full-width">
{totalCurrentFriendListCount > 10 && (
<>
<SearchBar2024
<SearchBar
clearButton
searchButton
placeholder="Search by name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { Suspense } from 'react';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import SuggestedContactList from './SuggestedContactList';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import VoterActions from '../../actions/VoterActions';
import apiCalming from '../../common/utils/apiCalming';
import { renderLog } from '../../common/utils/logging';
Expand Down Expand Up @@ -269,7 +269,7 @@ class SuggestedContactListWithController extends React.Component {
)}
{voterContactEmailListCount > 10 && (
<>
<SearchBar2024
<SearchBar
clearButton
searchButton
placeholder="Search by name, email, city or state code"
Expand Down
135 changes: 135 additions & 0 deletions src/js/components/Search/SearchBar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { CancelOutlined, Search } from '@mui/icons-material';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import styled from 'styled-components';
import { blurTextFieldAndroid, focusTextFieldAndroid, isIPhoneMiniOrSmaller } from '../../common/utils/cordovaUtils';
import { renderLog } from '../../common/utils/logging';

/* eslint-disable jsx-a11y/control-has-associated-label */

export default class SearchBar extends Component {
constructor (props) {
super(props);

this.state = {
searchString: '',
};

this.handleKeyPress = this.handleKeyPress.bind(this);
this.updateResults = this.updateResults.bind(this);
this.clearQuery = this.clearQuery.bind(this);
}

componentDidMount () {
// console.log("SearchBar, this.props.clearSearchTextNow:", this.props.clearSearchTextNow);
if (this.props.clearSearchTextNow) {
if (this.props.clearFunction) {
this.props.clearFunction();
}
const { searchString } = this.state;
if (searchString) {
this.setState({
searchString: '',
});
}
}
}

componentDidUpdate (prevProps) {
if (this.props.clearSearchTextNow !== prevProps.clearSearchTextNow) {
if (this.props.clearSearchTextNow) {
if (this.props.clearFunction) {
this.props.clearFunction();
}
const { searchString } = this.state;
if (searchString) {
this.setState({
searchString: '',
});
}
}
}
}

componentWillUnmount () {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}

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

clearQuery () {
this.props.clearFunction();
this.setState({ searchString: '' });
}

updateResults (event) {
const searchString = event.target.value;
this.setState({
searchString,
});
}

render () {
renderLog('SearchBar'); // Set LOG_RENDER_EVENTS to log all renders
const { clearButton, placeholder, searchButton } = this.props;
const { searchString } = this.state;
return (
<div className="search-bar clearfix">
<SearchInput
id="search_input"
type="text"
className="form-control"
placeholder={placeholder}
value={searchString}
onKeyDown={this.handleKeyPress}
onChange={this.updateResults}
onFocus={() => focusTextFieldAndroid('SearchBar')}
onBlur={blurTextFieldAndroid}
/>
<div className="search-bar-options">
{(clearButton && searchString && searchString.length > 0) && (
<button
className="search-clear-btn"
onClick={this.clearQuery}
type="button"
id="search-clear"
>
<CancelOutlined />
</button>
)}
{(searchButton) && (
<button
className="search-options-btn"
type="button"
id="search"
style={{ paddingLeft: 0 }}
>
<Search />
</button>
)}
</div>
</div>
);
}
}
SearchBar.propTypes = {
clearButton: PropTypes.bool,
clearFunction: PropTypes.func.isRequired,
clearSearchTextNow: PropTypes.bool,
placeholder: PropTypes.string,
searchButton: PropTypes.bool,
searchFunction: PropTypes.func.isRequired,
searchUpdateDelayTime: PropTypes.number.isRequired,
};

const SearchInput = styled('input')`
${isIPhoneMiniOrSmaller() ? 'font-size: 0.8rem' : ''};
`;
4 changes: 2 additions & 2 deletions src/js/components/Settings/VoterGuideListSearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SearchTitle } from '../../common/components/Style/FilterStyles';
import { renderLog } from '../../common/utils/logging';
import BallotStore from '../../stores/BallotStore';
import voterGuideSearchPriority from '../../utils/voterGuideSearchPriority';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import BallotItemForAddPositions from './BallotItemForAddPositions';

const DelayedLoad = React.lazy(() => import(/* webpackChunkName: 'DelayedLoad' */ '../../common/components/Widgets/DelayedLoad'));
Expand Down Expand Up @@ -164,7 +164,7 @@ class VoterGuideListSearchResults extends Component {
<div className="ballot_search">
<div>
<div className="u-padding-bottom--sm">
<SearchBar2024
<SearchBar
clearButton
clearFunction={this.clearFunction}
clearSearchTextNow={clearSearchTextNow}
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/VoterGuide/VoterGuideFollowers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import VoterGuideStore from '../../stores/VoterGuideStore';
import VoterStore from '../../stores/VoterStore';
import { renderLog } from '../../common/utils/logging';
import LoadingWheel from '../../common/components/Widgets/LoadingWheel';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import { PageContentContainer } from '../Style/pageLayoutStyles';
import GuideList from './GuideList';

Expand Down Expand Up @@ -203,7 +203,7 @@ class VoterGuideFollowers extends Component {
{/* Search Box */}
{voterGuideFollowersList && voterGuideFollowersList.length > 0 && (
<SearchInputWrapper>
<SearchBar2024
<SearchBar
clearButton
clearFunction={this.clearSearchBarFunction}
placeholder="Search these followers"
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/VoterGuide/VoterGuideFollowing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { renderLog } from '../../common/utils/logging';
import OrganizationStore from '../../stores/OrganizationStore';
import VoterGuideStore from '../../stores/VoterGuideStore';
import VoterStore from '../../stores/VoterStore';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import GuideList from './GuideList';

const DelayedLoad = React.lazy(() => import(/* webpackChunkName: 'DelayedLoad' */ '../../common/components/Widgets/DelayedLoad'));
Expand Down Expand Up @@ -239,7 +239,7 @@ class VoterGuideFollowing extends Component {
{/* Search Box */}
{voterGuideFollowedList && voterGuideFollowedList.length > 0 && (
<SearchInputWrapper>
<SearchBar2024
<SearchBar
clearButton
clearFunction={this.clearSearchBarFunction}
placeholder="Search these voter guides"
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/VoterGuide/VoterGuidePositionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import apiCalming from '../../common/utils/apiCalming';
import arrayContains from '../../common/utils/arrayContains';
import { getTodayAsInteger } from '../../common/utils/dateFormat';
import { renderLog } from '../../common/utils/logging';
import SearchBar2024 from '../Search/SearchBar2024';
import SearchBar from '../Search/SearchBar';
import FriendStore from '../../stores/FriendStore';
import OrganizationStore from '../../stores/OrganizationStore';
import NumberOfItemsFound from '../Widgets/NumberOfItemsFound';
Expand Down Expand Up @@ -466,7 +466,7 @@ class VoterGuidePositionList extends Component {
)}
{((positionList && (positionList.length > 10)) || isSearching) && (
<SearchBarWrapper>
<SearchBar2024
<SearchBar
clearButton
searchButton
placeholder="Search by name, office or state"
Expand Down
Loading

0 comments on commit 6898daa

Please sign in to comment.