Files
old-kivi/web/index.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-11-07 11:17:48 +01:00
import React from 'react';
2017-04-08 02:32:48 +02:00
import {render} from 'react-dom';
2016-11-07 11:17:48 +01:00
import Main from './components/Main';
2017-04-08 05:11:45 +02:00
const getInitialState = (url) => {
console.log('PARSING URL:', url);
const params = window.location.search.substr(1).split("&");
const initialState = {
rooms: {},
category: {}
}
for(const param of params) {
const [key, value] = param.split("=");
2017-04-09 23:39:38 +02:00
console.log('analyzing param ', key, value);
2017-04-08 05:11:45 +02:00
if (key === "rooms" && value !== '') {
2017-04-09 23:39:38 +02:00
console.log("IT's ROOMS");
2017-04-08 05:11:45 +02:00
value.split(",").forEach(k => {
2017-04-09 23:39:38 +02:00
console.log("IT's ROOMS", k);
2017-04-08 05:11:45 +02:00
initialState.rooms[parseInt(k)] = true;
});
}
if (key === "category" && value !== '') {
value.split(",").forEach(k => {
initialState.category[parseInt(k)] = true;
});
}
if (key === "sort") {
initialState.sort = value;
}
if (key === "bounds") {
initialState.bounds = value;
}
if (key === "listingId") {
initialState.listingId = value;
}
2017-04-09 23:39:38 +02:00
if (key === "zoom") {
initialState.zoom = parseInt(value);
}
2017-04-08 05:11:45 +02:00
}
console.log('initial state dump', initialState);
2017-04-09 23:39:38 +02:00
console.log('initial state ROOMS', initialState.rooms);
2017-04-08 05:11:45 +02:00
return initialState;
}
const main = (<Main initialState={getInitialState(window.location)}/>);
render(main, document.getElementById('root'));
2016-11-07 11:17:48 +01:00