Skip to content
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

Merged
merged 5 commits into from
Jun 6, 2017
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
12 changes: 0 additions & 12 deletions src/components/search_bar.jsx

This file was deleted.

12 changes: 12 additions & 0 deletions src/components/search_button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

const SearchButton = (props) => {
const handle = () => {
props.clickHandler(props.currentGHouse);
};

return (
<button onClick={handle}>{props.currentGHouse}</button>
);
};
export default SearchButton;
18 changes: 18 additions & 0 deletions src/components/search_list.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import SearchButton from './search_button.jsx';

const SearchList = props =>
(
<div>
{props.db.map(guestHouses =>
// const boundItemClick = handleClick.bind(this, guestHouses.name);
<SearchButton
key={guestHouses.name}
clickHandler={props.updateCurrent}
currentGHouse={guestHouses.name}
/>,
)}
</div>
);

export default SearchList;
25 changes: 22 additions & 3 deletions src/containers/select_guesthouse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@ 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: {},
title: 'PAS',
tagLine: 'Park & Sleep',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are title and tagLine ever change? if not, then its pointless to put them in a state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are going to be changed (header will update based on these values). Next PR.

guestHouseList: [],
currentGuestHouse: {},
};
this.currentGuestHouse = this.currentGuestHouse.bind(this);
}

currentGuestHouse(guestHouse) {
const current = this.state.db.filter((GHouse) => {
if (GHouse.name === guestHouse) {
return GHouse;
}
return current;
});
this.setState({
currentGuestHouse: current,
});
}

componentDidMount() {
axios.get('/api')
.then((res) => {
// console.log(res.data);
this.setState({ db: res.data });
});
}
Expand All @@ -26,7 +43,9 @@ class SelectGuesthouse extends Component {
<div>
<Header />
<TextBox />
<SearchBar guesthouses={this.state.db} />
<SearchList
db={this.state.guestHouseList}
updateCurrent={this.currentGuestHouse} />
</div>
);
}
Expand Down