Router WIP
This commit is contained in:
@@ -5,11 +5,13 @@ import ListingDetails from './ListingDetails';
|
||||
import { pacSelectFirst } from '../helpers/googleMaps';
|
||||
import { loadProperties, loadSeen, loadListing} from '../lib/api'
|
||||
import { handleMessage } from '../lib/handlers'
|
||||
import Router from '../lib/router';
|
||||
|
||||
class Main extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
|
||||
const state = {
|
||||
listingDetails: false,
|
||||
listings: (new Map()),
|
||||
imageIndex: 0,
|
||||
@@ -19,7 +21,18 @@ class Main extends React.Component {
|
||||
rooms: {},
|
||||
category: {}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (props.initialState) {
|
||||
state.filters.rooms = props.initialState.rooms;
|
||||
state.filters.category = props.initialState.category;
|
||||
state.sort = props.initialState.sort || state.sort;
|
||||
state.listingId = props.initialState.listingId;
|
||||
state.listingDetails = true;
|
||||
}
|
||||
|
||||
this.state = state;
|
||||
this.router = new Router(this);
|
||||
}
|
||||
|
||||
dispatch ({type, action = {}}) {
|
||||
@@ -93,6 +106,22 @@ class Main extends React.Component {
|
||||
console.log('idle');
|
||||
this.dispatch({type: 'MAP_IDLE'});
|
||||
});
|
||||
|
||||
|
||||
// TODO: if state contains listingId reload
|
||||
//
|
||||
|
||||
if (this.state.listingId) {
|
||||
|
||||
console.log("IT ISSSSS");
|
||||
loadListing(this.state.listingId).then(l => l.text()).then(l => {
|
||||
console.log('listing loaded', l);
|
||||
this.dispatch({type: 'VIEW_LISTING_DETAILS', action: {
|
||||
id: this.state.listingId,
|
||||
listing: JSON.parse(l)
|
||||
}});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
removeAllMarkers () {
|
||||
|
||||
Reference in New Issue
Block a user