Router WIP
This commit is contained in:
45
web/index.js
45
web/index.js
@@ -2,5 +2,48 @@ import React from 'react';
|
||||
import {render} from 'react-dom';
|
||||
import Main from './components/Main';
|
||||
|
||||
render(<Main />, document.getElementById('root'));
|
||||
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("=");
|
||||
if (key === "rooms" && value !== '') {
|
||||
value.split(",").forEach(k => {
|
||||
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") {
|
||||
// TODO: save bounds
|
||||
initialState.bounds = value;
|
||||
}
|
||||
|
||||
if (key === "listingId") {
|
||||
initialState.listingId = value;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('initial state dump', initialState);
|
||||
return initialState;
|
||||
}
|
||||
|
||||
const main = (<Main initialState={getInitialState(window.location)}/>);
|
||||
|
||||
render(main, document.getElementById('root'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user