File tree Expand file tree Collapse file tree 4 files changed +52
-15
lines changed Expand file tree Collapse file tree 4 files changed +52
-15
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ const SearchButton = ( props ) => {
4
+ const handle = ( ) => {
5
+ props . clickHandler ( props . currentGHouse ) ;
6
+ } ;
7
+
8
+ return (
9
+ < button onClick = { handle } > { props . currentGHouse } </ button >
10
+ ) ;
11
+ } ;
12
+ export default SearchButton ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import SearchButton from './search_button.jsx' ;
3
+
4
+ const SearchList = props =>
5
+ (
6
+ < div >
7
+ { props . db . map ( guestHouses =>
8
+ // const boundItemClick = handleClick.bind(this, guestHouses.name);
9
+ < SearchButton
10
+ key = { guestHouses . name }
11
+ clickHandler = { props . updateCurrent }
12
+ currentGHouse = { guestHouses . name }
13
+ /> ,
14
+ ) }
15
+ </ div >
16
+ ) ;
17
+
18
+ export default SearchList ;
Original file line number Diff line number Diff line change @@ -3,20 +3,37 @@ import axios from 'axios';
3
3
4
4
import Header from '../components/header.jsx' ;
5
5
import TextBox from '../components/text_box.jsx' ;
6
- import SearchBar from '../components/search_bar .jsx' ;
6
+ import SearchList from '../components/search_list .jsx' ;
7
7
8
8
9
9
class SelectGuesthouse extends Component {
10
10
constructor ( props ) {
11
11
super ( props ) ;
12
12
this . state = {
13
- db : { } ,
13
+ title : 'PAS' ,
14
+ tagLine : 'Park & Sleep' ,
15
+ guestHouseList : [ ] ,
16
+ currentGuestHouse : { } ,
14
17
} ;
18
+ this . currentGuestHouse = this . currentGuestHouse . bind ( this ) ;
19
+ }
20
+
21
+ currentGuestHouse ( guestHouse ) {
22
+ const current = this . state . db . filter ( ( GHouse ) => {
23
+ if ( GHouse . name === guestHouse ) {
24
+ return GHouse ;
25
+ }
26
+ return current ;
27
+ } ) ;
28
+ this . setState ( {
29
+ currentGuestHouse : current ,
30
+ } ) ;
15
31
}
16
32
17
33
componentDidMount ( ) {
18
34
axios . get ( '/api' )
19
35
. then ( ( res ) => {
36
+ // console.log(res.data);
20
37
this . setState ( { db : res . data } ) ;
21
38
} ) ;
22
39
}
@@ -26,7 +43,9 @@ class SelectGuesthouse extends Component {
26
43
< div >
27
44
< Header />
28
45
< TextBox />
29
- < SearchBar guesthouses = { this . state . db } />
46
+ < SearchList
47
+ db = { this . state . guestHouseList }
48
+ updateCurrent = { this . currentGuestHouse } />
30
49
</ div >
31
50
) ;
32
51
}
You can’t perform that action at this time.
0 commit comments