File tree 4 files changed +57
-42
lines changed
4 files changed +57
-42
lines changed Original file line number Diff line number Diff line change @@ -9,17 +9,37 @@ import { connect } from 'react-redux';
9
9
import { bindActionCreators } from 'redux' ;
10
10
import * as actions from '../actions/actions' ;
11
11
12
+ function formatStoreType ( type ) {
13
+ switch ( type ) {
14
+ case 'DestinationStore' :
15
+ return 'Destination Store' ;
16
+ case 'LocalSkyStore' :
17
+ return 'Local Sky Store' ;
18
+ default :
19
+ // return a sane default if the type isn't recognised
20
+ return 'Local Sky Store' ;
21
+ }
22
+ }
23
+
12
24
class LocatorContainer extends Component {
13
25
render ( ) {
14
26
const markers = this . props . storesFound . map ( ( store ) => {
15
27
return [ parseFloat ( store . Latitude ) , parseFloat ( store . Longitude ) ]
16
28
} )
17
29
30
+ const resultInfos = this . props . storesFound . map ( ( store ) => {
31
+ return Object . assign ( { } , store , {
32
+ _TypeFormatted : formatStoreType ( store . Type )
33
+ } )
34
+ } )
35
+
36
+ console . log ( "resultInfos" , resultInfos )
37
+
18
38
return (
19
39
< div >
20
40
< MapSearch onSearchPostcode = { this . props . actions . fetchStores } />
21
41
< button className = "btn btn-secondary btn-block mb-4 hidden-sm-up" > View Map</ button >
22
- < Results />
42
+ { resultInfos . length > 0 ? < Results resultInfos = { resultInfos } /> : 'No results' }
23
43
< MyMap markers = { markers } />
24
44
</ div >
25
45
) ;
Original file line number Diff line number Diff line change 1
- .results {
2
- /*margin: 0;
3
- padding: 0;
4
- list-style-type: none;*/
5
- /*overflow-y: scroll;*/
6
- }
7
-
8
- .result {
1
+ .result-wrapper {
9
2
margin-bottom : 1rem ;
10
3
padding : 0.6rem ;
11
4
}
12
5
13
- .result-inner {
14
- box-shadow : 0 1px 10px 0 rgba (0 , 0 , 0 , .2 );
15
- padding : 1.2rem ;
16
- }
17
-
18
- .result h1 {
19
- margin-bottom : 1rem ;
20
- }
21
-
22
- .result .distance {
23
- margin-bottom : 0.5rem ;
24
- }
25
-
26
- .result .address ,
27
- .result .telephone
28
- {
29
- color : # 999 ;
6
+ .result {
7
+ min-height : 270px ;
30
8
}
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import './Result.css' ;
3
+ import PropTypes from 'prop-types' ;
3
4
4
5
class Result extends Component {
5
6
render ( ) {
7
+ const { resultInfo : data } = this . props ;
6
8
return (
7
- < div { ...this . props } >
8
- < div className = "result" >
9
- < div className = "result-inner" >
10
- < h1 className = "h3" > Leeds</ h1 >
11
- < div className = "distance" > 0.2 Miles / 0.4 Km</ div >
12
- < div className = "address" > 123 Leeds Rd, Leeds, LS1 62Q</ div >
13
- < div className = "telephone" > 0113 123 1234</ div >
9
+ < div className = "result-wrapper" >
10
+ < div className = "card result" >
11
+ < div className = "card-block" >
12
+ < h4 className = "card-title" > { data . StoreName } </ h4 >
13
+ < h6 className = "card-subtitle mb-3 text-muted" > { data . _TypeFormatted } </ h6 >
14
+ < p className = "card-text" >
15
+ { data . Address1 } < br />
16
+ { data . Address2 &&
17
+ < span >
18
+ { data . Address2 } < br />
19
+ </ span >
20
+ }
21
+ { data . City } < br />
22
+ { data . Postcode } < br />
23
+ { data . Telephone }
24
+ </ p >
25
+ < a target = "_blank" href = { data . MapUrl } className = "card-link" > Directions</ a >
14
26
</ div >
15
27
</ div >
16
28
</ div >
17
29
) ;
18
30
}
19
31
}
20
32
33
+ Result . propTypes = {
34
+ resultInfo : PropTypes . object . isRequired
35
+ } ;
36
+
21
37
export default Result ;
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import './Results.css' ;
3
3
import Slider from 'react-slick' ;
4
+ import PropTypes from 'prop-types' ;
4
5
5
6
import Result from './Result' ;
6
7
7
- class Sidebar extends Component {
8
+ class Results extends Component {
8
9
render ( ) {
9
10
const settings = {
10
11
dots : true ,
@@ -35,16 +36,16 @@ class Sidebar extends Component {
35
36
36
37
return (
37
38
< Slider { ...settings } >
38
- < Result />
39
- < Result />
40
- < Result />
41
- < Result />
42
- < Result />
43
- < Result />
44
- < Result />
39
+ { this . props . resultInfos . map ( ( resultInfo , idx ) =>
40
+ < div key = { `result-${ idx } ` } > < Result resultInfo = { resultInfo } /> </ div >
41
+ ) }
45
42
</ Slider >
46
43
) ;
47
44
}
48
45
}
49
46
50
- export default Sidebar ;
47
+ Results . propTypes = {
48
+ resultInfos : PropTypes . array . isRequired
49
+ } ;
50
+
51
+ export default Results ;
You can’t perform that action at this time.
0 commit comments