Reorganize & reformat
This commit is contained in:
56
web/src/lib/api.js
Normal file
56
web/src/lib/api.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import fetch from 'isomorphic-fetch'
|
||||
|
||||
export const loadListing = id => {
|
||||
let url = `http://localhost:3001/api/search/listings/${id}`
|
||||
|
||||
return fetch(
|
||||
url,
|
||||
{
|
||||
//credentials: 'include'
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export const loadProperties = (
|
||||
{
|
||||
bounds,
|
||||
minPrice = '',
|
||||
maxPrice = '',
|
||||
minSize = '',
|
||||
maxSize = '',
|
||||
rooms = {},
|
||||
category = {},
|
||||
page = 1,
|
||||
pins = false,
|
||||
sort = ''
|
||||
}
|
||||
) => {
|
||||
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}&pins=${pins}&sort=${sort}`
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user