Welcome page
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import React from 'react'
|
||||
import {render} from 'react-dom'
|
||||
import Main from './components/Main'
|
||||
import Welcome from './components/Welcome'
|
||||
|
||||
const getInitialState = url => {
|
||||
console.log('PARSING URL:', url)
|
||||
const params = window.location.search.substr(1).split('&')
|
||||
|
||||
const initialState = {
|
||||
@@ -13,16 +13,15 @@ const getInitialState = url => {
|
||||
|
||||
for (const param of params) {
|
||||
const [key, value] = param.split('=')
|
||||
console.log('analyzing param ', key, value)
|
||||
if (key === 'rooms' && value !== '') {
|
||||
console.log("IT's ROOMS")
|
||||
initialState.rooms = {}
|
||||
value.split(',').forEach(k => {
|
||||
console.log("IT's ROOMS", k)
|
||||
initialState.rooms[parseInt(k)] = true
|
||||
})
|
||||
}
|
||||
|
||||
if (key === 'category' && value !== '') {
|
||||
initialState.category = {}
|
||||
value.split(',').forEach(k => {
|
||||
initialState.category[parseInt(k)] = true
|
||||
})
|
||||
@@ -40,6 +39,10 @@ const getInitialState = url => {
|
||||
initialState.listingId = value
|
||||
}
|
||||
|
||||
if (key === 'type') {
|
||||
initialState.type = value
|
||||
}
|
||||
|
||||
if (key === 'zoom') {
|
||||
initialState.zoom = parseInt(value)
|
||||
}
|
||||
@@ -52,6 +55,25 @@ const getInitialState = url => {
|
||||
return initialState
|
||||
}
|
||||
|
||||
const main = <Main initialState={getInitialState(window.location)} />
|
||||
const root = document.getElementById('root')
|
||||
const initialState = getInitialState(window.location)
|
||||
|
||||
render(main, document.getElementById('root'))
|
||||
const renderMain = (additionalState = {}) => {
|
||||
const main = <Main initialState={{...initialState, ...additionalState}} />
|
||||
render(main, root)
|
||||
}
|
||||
|
||||
if (Object.keys(initialState).length === 2 &&
|
||||
window.localStorage.getItem('lastLoad') == null) {
|
||||
const onSearch = ({bounds, type, location}) => {
|
||||
window.location = `/?bounds=${bounds}&type=${type}`
|
||||
//renderMain({
|
||||
//bounds,
|
||||
//type
|
||||
//})
|
||||
}
|
||||
const welcome = <Welcome onSearch={onSearch} />
|
||||
render(welcome, root)
|
||||
} else {
|
||||
renderMain()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user