Filters done
This commit is contained in:
@@ -4,18 +4,24 @@ export const loadProperties = ({
|
||||
bounds,
|
||||
minPrice = '',
|
||||
maxPrice = '',
|
||||
minSize = '',
|
||||
maxSize = '',
|
||||
rooms
|
||||
minSize = '',
|
||||
maxSize = '',
|
||||
rooms = {},
|
||||
category = {}
|
||||
}) => {
|
||||
const allRooms = Object
|
||||
.keys(rooms)
|
||||
.filter((v) => rooms[v])
|
||||
.join(',');
|
||||
|
||||
const allCategories = Object
|
||||
.keys(category)
|
||||
.filter((v) => category[v])
|
||||
.join(',');
|
||||
|
||||
// TODO: handle errors
|
||||
//return fetch(process.env.API_URL + '/api/search', {
|
||||
return fetch(`http://localhost:3001/api/search?bounds=${bounds}&minPrice=${minPrice}&maxPrice=${maxPrice}&rooms=${allRooms}&minSize=${minSize}&maxSize=${maxSize}`, {
|
||||
return fetch(`http://localhost:3001/api/search?bounds=${bounds}&minPrice=${minPrice}&maxPrice=${maxPrice}&rooms=${allRooms}&minSize=${minSize}&maxSize=${maxSize}&category=${allCategories}`, {
|
||||
//credentials: 'include'
|
||||
});
|
||||
|
||||
|
||||
@@ -99,7 +99,6 @@ const searchPlaceChanged = ({ type, action }, component) => {
|
||||
|
||||
const setRooms = ({ type, action }, component) => {
|
||||
const prevRooms = component.state.filters.rooms || {};
|
||||
console.log('BERORE ROOMS');
|
||||
|
||||
component.setState(
|
||||
{
|
||||
@@ -112,14 +111,12 @@ const setRooms = ({ type, action }, component) => {
|
||||
}
|
||||
},
|
||||
() => {
|
||||
console.log('after rooms');
|
||||
component.refreshListings();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const updateSearch = ({ type, action }, component) => {
|
||||
console.log("updating search");
|
||||
component.setState(
|
||||
{
|
||||
filters: {
|
||||
@@ -134,6 +131,26 @@ const updateSearch = ({ type, action }, component) => {
|
||||
);
|
||||
};
|
||||
|
||||
const setCategory = ({type, action}, component) => {
|
||||
|
||||
const prevCategory = component.state.filters.category || {};
|
||||
|
||||
component.setState(
|
||||
{
|
||||
filters: {
|
||||
...component.state.filters,
|
||||
category: {
|
||||
...prevCategory,
|
||||
[action.category]: !prevCategory[action.category]
|
||||
}
|
||||
}
|
||||
},
|
||||
() => {
|
||||
component.refreshListings();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const handlers = {
|
||||
SET_MIN_PRICE: setMinPrice,
|
||||
SET_MAX_PRICE: setMaxPrice,
|
||||
@@ -147,7 +164,8 @@ const handlers = {
|
||||
SEARCH_PLACE_CHANGED: searchPlaceChanged,
|
||||
SET_ROOMS: setRooms,
|
||||
VIEW_LISTING_DETAILS: viewListingDetails,
|
||||
UPDATE_SEARCH: updateSearch
|
||||
UPDATE_SEARCH: updateSearch,
|
||||
SET_CATEGORY: setCategory
|
||||
};
|
||||
|
||||
export const handleMessage = ({ type, action }, component) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const formatPrice = (p) => {
|
||||
if (p === -1) {
|
||||
if (isNaN(p)) {
|
||||
return 'Po dogovoru'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user