Skip to content

Commit

Permalink
Merge pull request #41 from andela/ft-user-get-instant-result-161217628
Browse files Browse the repository at this point in the history
#161217628 User can search instantly on the homepage
  • Loading branch information
Chieze-Franklin committed Oct 18, 2018
2 parents 6efb29f + 68870ee commit e56f9fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/src/modules/Home/container/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class Home extends Component {
event.preventDefault();
this.props.clearTeams();
this.loadMore(this.state.searchInput);
this.setState(() => ({ offset: 0, searchInput: '', searchOffset: 0 }));
this.setState(() => ({ offset: 0, searchOffset: 0 }));
}

handleSearchInput(event) {
Expand Down
15 changes: 13 additions & 2 deletions client/src/modules/common/Navbar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class Navbar extends Component {
super(props);
this.state = {
showSearchBar: false,
name: ''
name: '',
timeout: 0
};
this.toggleState = this.toggleState.bind(this);
this.handleSearch = this.handleSearch.bind(this);
this.signOut = this.signOut.bind(this);
this.handleAdminRequest = this.handleAdminRequest.bind(this);
this.instantSearch = this.instantSearch.bind(this);
}
componentDidMount = () => {
if (this.props.auth) {
Expand All @@ -64,6 +66,15 @@ class Navbar extends Component {
});
}

instantSearch(event) {
event.preventDefault();
if (this.timeout) clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.props.handleSubmit(event);
}, 500);
this.props.handleInput(event);
}

signOut(event) {
event.preventDefault();
this.props.signOut();
Expand Down Expand Up @@ -238,7 +249,7 @@ class Navbar extends Component {
type="search"
required
value={this.props.searchValue}
onChange={this.props.handleInput}
onChange={this.instantSearch}
/>
<label className="label-icon" htmlFor="search">
<i className="material-icons">search</i>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"fancy-log": "^1.3.2",
"file-loader": "^1.1.11",
"jwt-decode": "^2.2.0",
"lodash": "^4.17.11",
"materialize-css": "^1.0.0-rc.1",
"moment": "^2.22.1",
"morgan": "^1.9.0",
Expand Down

0 comments on commit e56f9fb

Please sign in to comment.