Files
old-kivi/web/lib/api.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-03-31 14:31:56 +02:00
import fetch from 'isomorphic-fetch';
2017-04-08 00:06:06 +02:00
export const loadListing = (id) => {
let url = `http://localhost:3001/api/search/listings/${id}`;
return fetch(url, {
//credentials: 'include'
});
};
2017-04-04 04:36:52 +02:00
export const loadProperties = ({
bounds,
minPrice = '',
maxPrice = '',
2017-04-05 02:02:43 +02:00
minSize = '',
maxSize = '',
rooms = {},
2017-04-07 04:02:01 +02:00
category = {},
2017-04-07 19:40:52 +02:00
page = 1,
2017-04-08 02:11:54 +02:00
pins = false,
sort = ''
2017-04-04 04:36:52 +02:00
}) => {
const allRooms = Object
.keys(rooms)
.filter((v) => rooms[v])
.join(',');
2017-04-05 02:02:43 +02:00
const allCategories = Object
.keys(category)
.filter((v) => category[v])
.join(',');
2017-03-31 14:31:56 +02:00
// TODO: handle errors
//return fetch(process.env.API_URL + '/api/search', {
2017-04-08 02:11:54 +02:00
let url = `http://localhost:3001/api/search/listings?bounds=${bounds}&minPrice=${minPrice}&maxPrice=${maxPrice}&rooms=${allRooms}&minSize=${minSize}&maxSize=${maxSize}&category=${allCategories}&page=${page}&pins=${pins}&sort=${sort}`
2017-04-07 04:02:01 +02:00
2017-04-07 19:40:52 +02:00
return fetch(url, {
2017-03-31 14:31:56 +02:00
//credentials: 'include'
});
}
2017-04-06 02:05:06 +02:00
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;
}