File tree Expand file tree Collapse file tree 7 files changed +64
-60
lines changed
Pages/Listings/Components Expand file tree Collapse file tree 7 files changed +64
-60
lines changed Original file line number Diff line number Diff line change @@ -2,15 +2,14 @@ import * as React from 'react'
2
2
import Geosuggest from 'react-geosuggest'
3
3
import { Subscribe } from 'unstated'
4
4
5
- import { SearchLocation } from 'src/Containers/SearchLocation'
6
-
5
+ import { Location } from 'src/Containers/Location'
7
6
import './geoInput.css'
8
7
9
8
export class GeoSuggest extends React . PureComponent {
10
9
public render ( ) {
11
10
return (
12
- < Subscribe to = { [ SearchLocation ] } >
13
- { ( { setPlace } : SearchLocation ) => (
11
+ < Subscribe to = { [ Location ] } >
12
+ { ( { setPlace } : Location ) => (
14
13
< Geosuggest
15
14
placeholder = "Enter a location"
16
15
onSuggestSelect = { place => setPlace ( place ) }
Original file line number Diff line number Diff line change
1
+ import { Container } from 'unstated'
2
+ import { Suggest } from 'react-geosuggest'
3
+
4
+ interface State {
5
+ center : {
6
+ lat : number
7
+ lng : number
8
+ }
9
+ marker : {
10
+ lat : number | null
11
+ lng : number | null
12
+ }
13
+ place : string [ ]
14
+ }
15
+
16
+ export class Location extends Container < State > {
17
+ public readonly state = {
18
+ center : {
19
+ lat : 52.0685 ,
20
+ lng : 19.9475
21
+ } ,
22
+ marker : {
23
+ lat : 52.0685 ,
24
+ lng : 52.0685
25
+ } ,
26
+ place : [ '' ]
27
+ }
28
+
29
+ public setPostion = ( lat : number , lng : number ) =>
30
+ this . setState ( { marker : { lat, lng } } )
31
+
32
+ public setPlace = async ( place : Suggest ) => {
33
+ if ( place ) {
34
+ const {
35
+ label,
36
+ location : { lat, lng }
37
+ } = place
38
+ const splitAddress = label . split ( ', ' )
39
+
40
+ await this . setState ( {
41
+ place : splitAddress ,
42
+ center : { lat : parseFloat ( lat ) , lng : parseFloat ( lng ) }
43
+ } )
44
+ }
45
+ }
46
+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ interface Props {
36
36
export class SearchListingsQuery extends React . PureComponent < Props > {
37
37
public render ( ) {
38
38
const { address } = this . props
39
-
39
+ console . log ( address )
40
40
return (
41
41
< Query query = { searchListingsQuery } variables = { { address } } >
42
42
{ ( { data, loading } ) => {
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
+ import { Subscribe } from 'unstated'
2
3
3
4
import { SearchListingsQuery } from 'src/Graphql/SearchListings'
4
5
import { ListingItem } from './Components/ListingItem'
6
+ import { Location } from 'src/Containers/Location'
5
7
6
8
import { Container } from './style'
7
- import { Subscribe } from 'unstated'
8
- import { SearchLocation } from 'src/Containers/SearchLocation'
9
- import { Postion } from 'src/Containers/Position'
10
9
11
10
export const ListingsList : React . SFC < { } > = ( ) => (
12
11
< Container >
13
- < Subscribe to = { [ SearchLocation , Postion ] } >
14
- { (
15
- { state : { place } } : SearchLocation ,
16
- { setPostion } : Postion
17
- ) => (
12
+ < Subscribe to = { [ Location ] } >
13
+ { ( { state : { place } , setPostion } : Location ) => (
18
14
< SearchListingsQuery address = { place } >
19
15
{ ( { listings, loading } ) =>
20
16
listings . map ( listing => (
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
2
import { withGoogleMap , GoogleMap , Marker } from 'react-google-maps'
3
3
import { Subscribe } from 'unstated'
4
- import { Postion } from 'src/Containers/Position'
4
+
5
+ import { Location } from 'src/Containers/Location'
5
6
6
7
export const Map = withGoogleMap ( ( ) => (
7
- < Subscribe to = { [ Postion ] } >
8
- { ( { state : { lat, lng } } ) => (
9
- < GoogleMap
10
- defaultZoom = { 7 }
11
- defaultCenter = { {
12
- lat : 52.0685 ,
13
- lng : 19.9475
14
- } }
15
- >
16
- < Marker position = { { lat, lng } } />
17
- </ GoogleMap >
18
- ) }
8
+ < Subscribe to = { [ Location ] } >
9
+ { ( { state : { center, marker, place } } : Location ) =>
10
+ ( console . log ( place . length , 'LENG' ) as any ) || (
11
+ < GoogleMap zoom = { place . length > 1 ? 13 : 6 } center = { center } >
12
+ { marker . lat && < Marker position = { marker } /> }
13
+ </ GoogleMap >
14
+ )
15
+ }
19
16
</ Subscribe >
20
17
) )
You can’t perform that action at this time.
0 commit comments