Search & show listings

This commit is contained in:
Edin Dazdarevic
2017-03-31 14:31:56 +02:00
parent c32e49e6c3
commit d6c2e857d0
16 changed files with 1598 additions and 35 deletions

13
web/lib/api.js Normal file
View File

@@ -0,0 +1,13 @@
import fetch from 'isomorphic-fetch';
export const loadProperties = ({bounds, minPrice = 0}) => {
// TODO: handle errors
//return fetch(process.env.API_URL + '/api/search', {
return fetch(`http://localhost:3001/api/search?bounds=${bounds}&minPrice=${minPrice}`, {
//credentials: 'include'
});
//const body = await res.text();
//return JSON.parse(body);
}

43
web/lib/handlers.js Normal file
View File

@@ -0,0 +1,43 @@
const setMinPrice = ({type, action}, component) => {
component.setState({
filters: {
minPrice: parseFloat(action.minPrice) || 0
}
})
}
const viewListingDetails= ({type, action}, component) => {
component.setState({
listingDetails: true,
listingId: action.id,
descriptionExpanded: false
})
}
const listingsLoaded = ({type, action}, component) => {
component.setState({
listings: action.listings
});
}
const expandDescription = ({type, action}, component) => {
component.setState({
descriptionExpanded: true
});
}
const handlers = {
'SET_MIN_PRICE': setMinPrice,
'LISTINGS_LOADED': listingsLoaded,
'EXPAND_DESCRIPTION': expandDescription,
'VIEW_LISTING_DETAILS': viewListingDetails
}
export const handleMessage = ({type, action}, component) => {
if (!handlers[type]) {
throw new `Unhandled message: ${type}`;
}
return handlers[type]({type, action}, component);
}