-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/select g house #34
Changes from 2 commits
cfae191
513a60b
16ca391
e42b09d
01c2d4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
|
||
const SearchList = (props) => { | ||
const handleClick = (guestHouse) => { | ||
props.updateCurrent(guestHouse); | ||
}; | ||
console.log(props); | ||
|
||
return ( | ||
<div> | ||
{props.db.map((guestHouses) => { | ||
const boundItemClick = handleClick.bind(this, guestHouses.name); | ||
return ( | ||
<button | ||
key={guestHouses.name} | ||
onClick={boundItemClick}> | ||
{guestHouses.name} | ||
</button> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchList; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,35 @@ import axios from 'axios'; | |
|
||
import Header from '../components/header.jsx'; | ||
import TextBox from '../components/text_box.jsx'; | ||
import SearchBar from '../components/search_bar.jsx'; | ||
import SearchList from '../components/search_list.jsx'; | ||
|
||
|
||
class SelectGuesthouse extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
db: {}, | ||
db: [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe instead of db, use 'guestHousesList'? might be clearer for the reader There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good shout |
||
currentGuestHouse: {}, | ||
}; | ||
this.currentGuestHouse = this.currentGuestHouse.bind(this); | ||
} | ||
|
||
currentGuestHouse(guestHouse) { | ||
const current = this.state.db.filter((curr) => { | ||
if (curr.name === guestHouse) { | ||
return curr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curr and current? |
||
} | ||
return current; | ||
}); | ||
this.setState({ | ||
currentGuestHouse: current, | ||
}); | ||
} | ||
|
||
componentDidMount() { | ||
axios.get('/api') | ||
.then((res) => { | ||
// console.log(res.data); | ||
this.setState({ db: res.data }); | ||
}); | ||
} | ||
|
@@ -26,7 +41,9 @@ class SelectGuesthouse extends Component { | |
<div> | ||
<Header /> | ||
<TextBox /> | ||
<SearchBar guesthouses={this.state.db} /> | ||
<SearchList | ||
db={this.state.db} | ||
updateCurrent={this.currentGuestHouse} /> | ||
</div> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this button should be a different component and then the bind function wont be inside the map function