48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import fetch from 'isomorphic-fetch';
|
|
|
|
export const loadProperties = ({
|
|
bounds,
|
|
minPrice = '',
|
|
maxPrice = '',
|
|
minSize = '',
|
|
maxSize = '',
|
|
rooms = {},
|
|
category = {},
|
|
page = 1
|
|
}) => {
|
|
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', {
|
|
let url = `http://localhost:3001/api/search/listings?bounds=${bounds}&minPrice=${minPrice}&maxPrice=${maxPrice}&rooms=${allRooms}&minSize=${minSize}&maxSize=${maxSize}&category=${allCategories}&page=${page}`
|
|
|
|
//if (lastRecordId) {
|
|
//url += `&lastRecordId=${lastRecordId}`;
|
|
//}
|
|
|
|
return fetch(url, {
|
|
//credentials: 'include'
|
|
});
|
|
|
|
}
|
|
|
|
export const markSeen = (id) => {
|
|
const seen = JSON.parse(window.localStorage.getItem('seen') || '[]');
|
|
seen.push(id);
|
|
window.localStorage.setItem('seen', JSON.stringify(seen));
|
|
}
|
|
|
|
export const loadSeen = (id) => {
|
|
const seen = JSON.parse(window.localStorage.getItem('seen') || '[]');
|
|
return seen;
|
|
//return seen.findIndex(s => s === id) !== -1;
|
|
}
|