Skip to content

Commit 0c6bf63

Browse files
committed
Searching listings for guests and price
1 parent 7767866 commit 0c6bf63

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

client/src/Graphql/SearchListings/index.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ import gql from 'graphql-tag'
55
import { Listing } from 'src/graphql.schema'
66

77
export const searchListingsQuery = gql`
8-
query SearchListings($address: [String]) {
9-
searchListings(input: { address: $address }) {
8+
query SearchListings(
9+
$address: [String]
10+
$guests: Int
11+
$priceMin: Int
12+
$priceMax: Int
13+
) {
14+
searchListings(
15+
input: {
16+
address: $address
17+
guests: $guests
18+
priceMin: $priceMin
19+
priceMax: $priceMax
20+
}
21+
) {
1022
id
1123
name
1224
category
@@ -30,23 +42,30 @@ interface WithListings {
3042

3143
interface Props {
3244
address: string[]
45+
guests?: number
46+
priceMin?: number
47+
priceMax?: number
3348
children: (values: WithListings) => React.ReactNode
3449
}
3550

36-
export class SearchListingsQuery extends React.Component<Props> {
37-
public shouldComponentUpdate(nextProps: Props) {
38-
if (this.props.address !== nextProps.address) {
39-
return true
40-
}
51+
export class SearchListingsQuery extends React.PureComponent<Props> {
52+
// public shouldComponentUpdate(nextProps: Props) {
53+
// const { address, guests, priceMin, priceMax } = this.props
54+
// if (this.props.address !== nextProps.address) {
55+
// return true
56+
// }
4157

42-
return false
43-
}
58+
// return false
59+
// }
4460

4561
public render() {
46-
const { address } = this.props
62+
const { address, guests, priceMin, priceMax } = this.props
4763

4864
return (
49-
<Query query={searchListingsQuery} variables={{ address }}>
65+
<Query
66+
query={searchListingsQuery}
67+
variables={{ address, guests, priceMin, priceMax }}
68+
>
5069
{({ data, loading }) => {
5170
let listings: Listing[] = []
5271

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import { Subscribe } from 'unstated'
44
import { SearchListingsQuery } from 'src/Graphql/SearchListings'
55
import { ListingItem } from './Components/ListingItem'
66
import { Location } from 'src/Containers/Location'
7+
import { Filter } from 'src/Containers/Filter'
78

89
import { Container } from './style'
910

1011
export const ListingsList: React.SFC<{}> = () => (
1112
<Container>
12-
<Subscribe to={[Location]}>
13-
{({ state: { place }, setPostion }: Location) => (
14-
<SearchListingsQuery address={place}>
13+
<Subscribe to={[Location, Filter]}>
14+
{(
15+
{ state: { place }, setPostion }: Location,
16+
{ state: { ...filters } }: Filter
17+
) => (
18+
<SearchListingsQuery address={place} {...filters}>
1519
{({ listings, loading }) =>
1620
listings.map(listing => (
1721
<ListingItem

client/src/apollo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { ApolloLink } from 'apollo-link'
66
import { onError } from 'apollo-link-error'
77

88
const httpLink = createHttpLink({
9-
uri: 'https://airbnb-clone-mm.herokuapp.com'
10-
// uri: 'http://localhost:4000/'
9+
// uri: 'https://airbnb-clone-mm.herokuapp.com'
10+
uri: 'http://localhost:4000/'
1111
})
1212

1313
const authLink = setContext((_, { headers }) => {

0 commit comments

Comments
 (0)