Router WIP

This commit is contained in:
Edin Dazdarevic
2017-04-08 05:11:45 +02:00
parent b540f50e15
commit 562bbc638f
5 changed files with 99 additions and 7 deletions

View File

@@ -59,6 +59,8 @@ const viewListingDetails = ({ type, action }, component) => {
imageIndex: 0,
listing: action.listing
}, () => {
//window.history.pushState({}, '', `/listing/${action.id}`);
component.router.update();
markSeen(action.id);
const m = component.findMarker(action.id);
if (m) {

18
web/lib/router.js Normal file
View File

@@ -0,0 +1,18 @@
export default class Router {
constructor(comp) {
this.component = comp;
}
update () {
// Take the state from the component and update the URL
const {listingId, sort, minPrice, maxPrice, minSize, maxSize, filters: {rooms, category}} = this.component.state;
const bounds = this.component.map.getBounds().toUrlValue();
const params = [];
params.push(`listingId=${listingId}`);
params.push(`sort=${sort}`);
params.push(`bounds=${bounds}`);
params.push(`rooms=${Object.keys(rooms).filter(v => rooms[v]).join(",")}`);
params.push(`category=${Object.keys(category).filter(v => category[v]).join(",")}`);
window.history.pushState({}, '', `/?${params.join("&")}`);
}
}