Skip to content

Commit ac4e20a

Browse files
committed
Filling listings components with data from api
1 parent 51df13b commit ac4e20a

File tree

7 files changed

+202
-70
lines changed

7 files changed

+202
-70
lines changed

client/src/Graphql/Listing/index.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
)
Lines changed: 22 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,24 @@
11
import * as React from 'react'
22

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+
}

client/src/Pages/Listing/Components/Details/style.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export const Container = styled.div`
1010
export const Row = styled.div`
1111
display: flex;
1212
`
13+
export const TitleWrap = styled.div`
14+
width: 500px;
15+
`
1316
export const Title = styled.p`
1417
max-width: 500px;
1518
font-size: 30px;

client/src/Pages/Listing/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import { Image } from './Components/Image'
44
import { Row } from './Components/Row'
55
import { Details } from './Components/Details'
66
import { Reservation } from './Components/Reservation'
7+
import { RouteComponentProps } from 'react-router'
78

8-
export const Listing: React.SFC<{}> = () => (
9+
export const Listing: React.SFC<RouteComponentProps<{ id: string }>> = ({
10+
match: {
11+
params: { id }
12+
}
13+
}) => (
914
<>
1015
<Image />
1116

1217
<Row>
13-
<Details />
18+
<Details id={id} />
1419
<Reservation />
1520
</Row>
1621
</>

client/src/Pages/Listings/Components/ListingsList/Components/ListingItem/index.tsx

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,58 @@ import {
1515
VerySmallText
1616
} from './style'
1717

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' }}>
2046
<Container>
2147
<Image src="https://a0.muscache.com/im/pictures/126e41c4-2a1b-4251-b516-d239351126f7.jpg?aki_policy=large" />
2248

2349
<Row>
2450
<Details>
2551
<Subtitle>CAŁY APARTAMENT</Subtitle>
26-
<Title>Studio w Centrum przy Dworcy Gdynia</Title>
52+
<Title>{name}</Title>
2753

2854
<RoomsDetails>
29-
<SmallText>2 goście •</SmallText>
55+
<SmallText>{guests} goście •</SmallText>
3056
<SmallText>1 sypialnia •</SmallText>
31-
<SmallText>1 Łóżko •</SmallText>
57+
<SmallText>{beds} Łóżko •</SmallText>
3258
<SmallText>1 Łazienka</SmallText>
3359
</RoomsDetails>
3460

3561
<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+
))}
4065
</RoomsDetails>
4166
</Details>
4267

4368
<Pricing>
44-
<Title>90</Title>
69+
<Title>{price}</Title>
4570
<VerySmallText>za dzien</VerySmallText>
4671

4772
<Stars />

client/src/Pages/Listings/Components/ListingsList/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export const ListingsList: React.SFC<{}> = () => (
99
<Container>
1010
<ListingsQuery>
1111
{({ listings, loading }) =>
12-
listings.map(listing => <ListingItem key={listing.id} />)
12+
listings.map(listing => (
13+
<ListingItem key={listing.id} {...listing} />
14+
))
1315
}
1416
</ListingsQuery>
1517
</Container>

0 commit comments

Comments
 (0)