Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ import Status from "./components/Status";
import Mentor from "./components/Mentor";

class App extends Component {

constructor(props) {
super(props);
this.state = {
search: '',
}
}

search = (val) => {
this.setState({ search: val });
}

render() {
return (
<div className="App">
<Header />
<Header handleSearch={this.search} />
<Router />
{/* <Status /> */}
<Mentor />
<Mentor search={this.state.search} />
</div>
);
}
Expand Down
16 changes: 13 additions & 3 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ class Header extends Component {
constructor(props) {
super(props);
this.state = {
username: 'Hi!'
username: 'Hi!',
search: '',
}
}

user = (val) => {
this.setState({ username: val });
}

search = (event) => {
this.setState({ search: event.target.value });
}

submit = (event) => {
event.preventDefault();
this.props.handleSearch(this.state.search);
}

render() {
return (
<div className="main thememain-header">
Expand Down Expand Up @@ -42,8 +52,8 @@ class Header extends Component {
<a className="nav-link disabled" href="#" title="About">About</a>
</li>
</ul>
<form className="form-inline my-2 my-lg-0">
<input className="form-control mr-sm-2" type="search" placeholder="Search" />
<form className="form-inline my-2 my-lg-0" onSubmit={this.submit}>
<input className="form-control mr-sm-2" type="search" placeholder="Search" onChange={this.search} />
<button className="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
<Link to="/login">
Expand Down
9 changes: 8 additions & 1 deletion src/components/Mentor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ class Mentor extends Component {
});*/
}

getSearchedProducts() {
const { search } = this.props;
return search ? this.state.Product.filter(
(data) => data.name.toLowerCase().indexOf(search.toLowerCase()) !== -1
) : this.state.Product;
}


render() {
return (
<div className="main thememain-white">
<div className="container content-main">
<br />
<div className="row">
{this.state.Product.map((data) => {
{this.getSearchedProducts().map((data) => {
return <MentorList key={data.id} data={data} />
})}
</div>
Expand Down