File tree Expand file tree Collapse file tree 7 files changed +202
-70
lines changed
Listings/Components/ListingsList Expand file tree Collapse file tree 7 files changed +202
-70
lines changed Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+ import { Query } from 'react-apollo'
3
+ import gql from 'graphql-tag'
4
+
5
+ import { Listing } from 'src/graphql.schema'
6
+
7
+ export const listingQuery = gql `
8
+ query ListingQuery($id: ID!) {
9
+ listing(id: $id) {
10
+ id
11
+ name
12
+ category
13
+ description
14
+ price
15
+ beds
16
+ guests
17
+ lat
18
+ lng
19
+ amenities
20
+ }
21
+ }
22
+ `
23
+
24
+ interface WithListing {
25
+ listing : Listing | null
26
+ loading : boolean
27
+ }
28
+
29
+ interface Props {
30
+ id : string
31
+ children : ( values : WithListing ) => React . ReactNode | null
32
+ }
33
+
34
+ export class ListingQuery extends React . PureComponent < Props > {
35
+ public render ( ) {
36
+ const { id } = this . props
37
+
38
+ return (
39
+ < Query query = { listingQuery } variables = { { id } } >
40
+ { ( { data, loading } ) => {
41
+ let listing : Listing | null = null
42
+
43
+ if ( data && data . listing ) {
44
+ listing = data . listing
45
+ }
46
+
47
+ return this . props . children ( {
48
+ listing,
49
+ loading
50
+ } )
51
+ } }
52
+ </ Query >
53
+ )
54
+ }
55
+ }
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+
3
+ import { Br } from 'src/Components/Br'
4
+ import {
5
+ Container ,
6
+ Title ,
7
+ Row ,
8
+ User ,
9
+ Username ,
10
+ UserAvatar ,
11
+ Text ,
12
+ RoomDetails ,
13
+ GroupIcon ,
14
+ RoomDetailsText ,
15
+ BedIcon ,
16
+ DoorIcon ,
17
+ BathIcon ,
18
+ Description ,
19
+ TitleWrap
20
+ } from './style'
21
+
22
+ interface Props {
23
+ name : string
24
+ category : string
25
+ description : string
26
+ price : number
27
+ beds : number
28
+ guests : number
29
+ lat : number
30
+ lng : number
31
+ amenities : string [ ]
32
+ }
33
+
34
+ export const DetailsUI : React . SFC < Props > = ( {
35
+ name,
36
+ category,
37
+ description,
38
+ price,
39
+ beds,
40
+ guests,
41
+ lat,
42
+ lng,
43
+ amenities
44
+ } ) => (
45
+ < Container >
46
+ < Row >
47
+ < TitleWrap >
48
+ < Title > { name } </ Title >
49
+
50
+ < Text > Gdynia</ Text >
51
+ </ TitleWrap >
52
+ < User >
53
+ < UserAvatar src = "https://a0.muscache.com/im/pictures/ead1a702-12fc-4a19-81c6-0fd97ec7d08b.jpg?aki_policy=profile_x_medium" />
54
+
55
+ < Username > Marlena</ Username >
56
+ </ User >
57
+ </ Row >
58
+
59
+ < RoomDetails >
60
+ < GroupIcon />
61
+ < RoomDetailsText > { guests } goście</ RoomDetailsText >
62
+
63
+ < DoorIcon />
64
+ < RoomDetailsText > 1 sypialnia</ RoomDetailsText >
65
+
66
+ < BedIcon />
67
+ < RoomDetailsText > { beds } lozko</ RoomDetailsText >
68
+
69
+ < BathIcon />
70
+ < RoomDetailsText > 1 lazienka</ RoomDetailsText >
71
+ </ RoomDetails >
72
+
73
+ < Description > { description } </ Description >
74
+
75
+ < Br />
76
+ </ Container >
77
+ )
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
2
3
- import { Br } from 'src/Components/Br'
4
- import {
5
- Container ,
6
- Title ,
7
- Row ,
8
- User ,
9
- Username ,
10
- UserAvatar ,
11
- Text ,
12
- RoomDetails ,
13
- GroupIcon ,
14
- RoomDetailsText ,
15
- BedIcon ,
16
- DoorIcon ,
17
- BathIcon ,
18
- Description
19
- } from './style'
20
-
21
- export const Details : React . SFC < { } > = ( ) => (
22
- < Container >
23
- < Row >
24
- < div >
25
- < Title > Studio w Centrum przy Dworcu Gdynia</ Title >
26
-
27
- < Text > Gdynia</ Text >
28
- </ div >
29
- < User >
30
- < UserAvatar src = "https://a0.muscache.com/im/pictures/ead1a702-12fc-4a19-81c6-0fd97ec7d08b.jpg?aki_policy=profile_x_medium" />
31
-
32
- < Username > Marlena</ Username >
33
- </ User >
34
- </ Row >
35
-
36
- < RoomDetails >
37
- < GroupIcon />
38
- < RoomDetailsText > 2 goście</ RoomDetailsText >
39
-
40
- < DoorIcon />
41
- < RoomDetailsText > 1 sypialnia</ RoomDetailsText >
42
-
43
- < BedIcon />
44
- < RoomDetailsText > 1 lozko</ RoomDetailsText >
45
-
46
- < BathIcon />
47
- < RoomDetailsText > 1 lazienka</ RoomDetailsText >
48
- </ RoomDetails >
49
-
50
- < Description >
51
- Bardzo słoneczny i ciepły w pełni wyposażony apartament ok 25m2 w
52
- centrum Gdyni. Duży pokój z narożnikiem, aneks kuchenny, łazienka.
53
- Do dworca Gdynia Główna 7 min spacerem. Wszystko czego możesz chcieć
54
- na wakacjach i w podróży służbowej. Zapraszam :)
55
- </ Description >
56
-
57
- < Br />
58
- </ Container >
59
- )
3
+ import { ListingQuery } from 'src/Graphql/Listing'
4
+ import { DetailsUI } from './Details'
5
+
6
+ interface Props {
7
+ id : string
8
+ }
9
+
10
+ export class Details extends React . Component < Props , { } > {
11
+ public render ( ) {
12
+ const { id } = this . props
13
+ return (
14
+ < ListingQuery id = { id } >
15
+ { ( { listing, loading } ) => {
16
+ if ( loading || ! listing ) {
17
+ return < div />
18
+ }
19
+ return < DetailsUI { ...listing } />
20
+ } }
21
+ </ ListingQuery >
22
+ )
23
+ }
24
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ export const Container = styled.div`
10
10
export const Row = styled . div `
11
11
display: flex;
12
12
`
13
+ export const TitleWrap = styled . div `
14
+ width: 500px;
15
+ `
13
16
export const Title = styled . p `
14
17
max-width: 500px;
15
18
font-size: 30px;
Original file line number Diff line number Diff line change @@ -4,13 +4,18 @@ import { Image } from './Components/Image'
4
4
import { Row } from './Components/Row'
5
5
import { Details } from './Components/Details'
6
6
import { Reservation } from './Components/Reservation'
7
+ import { RouteComponentProps } from 'react-router'
7
8
8
- export const Listing : React . SFC < { } > = ( ) => (
9
+ export const Listing : React . SFC < RouteComponentProps < { id : string } > > = ( {
10
+ match : {
11
+ params : { id }
12
+ }
13
+ } ) => (
9
14
< >
10
15
< Image />
11
16
12
17
< Row >
13
- < Details />
18
+ < Details id = { id } />
14
19
< Reservation />
15
20
</ Row >
16
21
</ >
Original file line number Diff line number Diff line change @@ -15,33 +15,58 @@ import {
15
15
VerySmallText
16
16
} from './style'
17
17
18
- export const ListingItem : React . SFC < { } > = ( ) => (
19
- < Link to = "/listing/1" style = { { textDecoration : 'none' } } >
18
+ interface Props {
19
+ id : number
20
+ name : string
21
+ category : string
22
+ description : string
23
+ price : number
24
+ beds : number
25
+ guests : number
26
+ lat : number
27
+ lng : number
28
+ amenities : string [ ]
29
+ }
30
+
31
+ const getRoute = ( id : number ) => `/listing/${ id } `
32
+
33
+ export const ListingItem : React . SFC < Props > = ( {
34
+ id,
35
+ name,
36
+ category,
37
+ description,
38
+ price,
39
+ beds,
40
+ guests,
41
+ lat,
42
+ lng,
43
+ amenities
44
+ } ) => (
45
+ < Link to = { getRoute ( id ) } style = { { textDecoration : 'none' } } >
20
46
< Container >
21
47
< Image src = "https://a0.muscache.com/im/pictures/126e41c4-2a1b-4251-b516-d239351126f7.jpg?aki_policy=large" />
22
48
23
49
< Row >
24
50
< Details >
25
51
< Subtitle > CAŁY APARTAMENT</ Subtitle >
26
- < Title > Studio w Centrum przy Dworcy Gdynia </ Title >
52
+ < Title > { name } </ Title >
27
53
28
54
< RoomsDetails >
29
- < SmallText > 2 goście •</ SmallText >
55
+ < SmallText > { guests } goście •</ SmallText >
30
56
< SmallText > 1 sypialnia •</ SmallText >
31
- < SmallText > 1 Łóżko •</ SmallText >
57
+ < SmallText > { beds } Łóżko •</ SmallText >
32
58
< SmallText > 1 Łazienka</ SmallText >
33
59
</ RoomsDetails >
34
60
35
61
< RoomsDetails >
36
- < SmallText > WIFI •</ SmallText >
37
- < SmallText > Kuchnia •</ SmallText >
38
- < SmallText > Pralka •</ SmallText >
39
- < SmallText > Zmywarka</ SmallText >
62
+ { amenities . map ( ( amenitie , i ) => (
63
+ < SmallText key = { i } > { amenitie } •</ SmallText >
64
+ ) ) }
40
65
</ RoomsDetails >
41
66
</ Details >
42
67
43
68
< Pricing >
44
- < Title > 90 zł</ Title >
69
+ < Title > { price } zł</ Title >
45
70
< VerySmallText > za dzien</ VerySmallText >
46
71
47
72
< Stars />
Original file line number Diff line number Diff line change @@ -9,7 +9,9 @@ export const ListingsList: React.SFC<{}> = () => (
9
9
< Container >
10
10
< ListingsQuery >
11
11
{ ( { listings, loading } ) =>
12
- listings . map ( listing => < ListingItem key = { listing . id } /> )
12
+ listings . map ( listing => (
13
+ < ListingItem key = { listing . id } { ...listing } />
14
+ ) )
13
15
}
14
16
</ ListingsQuery >
15
17
</ Container >
You can’t perform that action at this time.
0 commit comments