Reorganize & reformat
This commit is contained in:
57
web/src/index.js
Normal file
57
web/src/index.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import React from 'react'
|
||||
import {render} from 'react-dom'
|
||||
import Main from './components/Main'
|
||||
|
||||
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('=')
|
||||
console.log('analyzing param ', key, value)
|
||||
if (key === 'rooms' && value !== '') {
|
||||
console.log("IT's ROOMS")
|
||||
value.split(',').forEach(k => {
|
||||
console.log("IT's ROOMS", 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') {
|
||||
initialState.bounds = value
|
||||
}
|
||||
|
||||
if (key === 'listingId') {
|
||||
initialState.listingId = value
|
||||
}
|
||||
|
||||
if (key === 'zoom') {
|
||||
initialState.zoom = parseInt(value)
|
||||
}
|
||||
|
||||
if (['minSize', 'maxSize', 'minPrice', 'maxPrice'].includes(key)) {
|
||||
initialState[key] = parseFloat(value)
|
||||
}
|
||||
}
|
||||
|
||||
return initialState
|
||||
}
|
||||
|
||||
const main = <Main initialState={getInitialState(window.location)} />
|
||||
|
||||
render(main, document.getElementById('root'))
|
||||
Reference in New Issue
Block a user