Commit c257a9cf authored by Denis Sedura's avatar Denis Sedura

Add main.js

parent df428d77
import React, { Component } from 'react'
import { enhanceNearbyStoreList } from '../NearbyStoreList'
import { enhanceMenuButton } from '../../components/MenuButton'
function enhanceMain(ComposedComponent, NearbyStoreList, MenuButton) {
const NearbyStoreListHOC = enhanceNearbyStoreList(NearbyStoreList)
const MenuButtonHOC = enhanceMenuButton(MenuButton)
return class Wrapper extends Component {
render() {
return (
<ComposedComponent {...this.props}>
<NearbyStoreListHOC />
<MenuButtonHOC />
</ComposedComponent>
)
}
}
}
export default enhanceMain
export { default as enhanceMain } from './Main'
......@@ -4,7 +4,7 @@ import { connect } from 'react-redux'
import { createSelector } from 'reselect'
import { storesSelector } from 'tipsi_api/selectors'
import { loadStores } from 'tipsi_api/actions'
import { withNavigation } from '@expo/ex-navigation'
import { isEqual } from 'lodash'
import { updateCurrentLocation } from '../../actions'
import sortStoresByDistance from '../../utils/sortStoresByDistance'
import unimplementedFeature from '../../utils/unimplementedFeature'
......@@ -13,32 +13,34 @@ function enhanceNearbyStoreList(ComposedComponent) {
class Wrapper extends Component {
static propTypes = {
navigator: PropTypes.object.isRequired,
nearbyStores: PropTypes.array.isRequired,
loadStores: PropTypes.func.isRequired,
updateCurrentLocation: PropTypes.func.isRequired,
}
shouldComponentUpdate(nextProps) {
return !isEqual(this.props, nextProps)
}
handlePressSettings = () => (
unimplementedFeature()
)
handleRowPress = (storeId, title) => (
this.props.navigator.push('Store', { storeId, title })
// this.props.navigator.push('Store', { storeId, title })
console.log('Push Store', title)
)
handleSubmitEditing = query => (
this.props.navigator.push('Search', { query })
// this.props.navigator.push('Search', { query })
console.log('Push Search', query)
)
handlePressSuggestion = suggestion => (
this.props.navigator.push('Search', { query: suggestion.name })
// this.props.navigator.push('Search', { query: suggestion.name })
console.log('Push suggestion', suggestion)
)
loadStores = () => {
this.props.loadStores()
}
render() {
return (
<ComposedComponent
......@@ -70,7 +72,7 @@ function enhanceNearbyStoreList(ComposedComponent) {
const mapDispatchToProps = { loadStores, updateCurrentLocation }
return connect(mapStateToProps, mapDispatchToProps)(withNavigation(Wrapper))
return connect(mapStateToProps, mapDispatchToProps)(Wrapper)
}
export default enhanceNearbyStoreList
......@@ -2,3 +2,4 @@ export { enhanceAppComponent } from './App'
export { enhanceInitialComponent } from './InitialScreen'
export { enhanceAgeConfirmation } from './AgeConfirmation'
export { enhanceNearbyStoreList } from './NearbyStoreList'
export { enhanceMain } from './Main'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { withNavigation } from '@expo/ex-navigation'
import { userSelector } from 'tipsi_api/selectors'
import { isEqual } from 'lodash'
// import Router from '../../navigation/Router'
import { openSidebarMenu, closeSidebarMenu } from '../../actions'
......@@ -12,30 +13,27 @@ function enhanceSidebarMenu(ComposedComponent) {
static propTypes = {
children: PropTypes.node.isRequired,
menuIsOpen: PropTypes.bool.isRequired,
navigation: PropTypes.object.isRequired,
openSidebarMenu: PropTypes.func.isRequired,
closeSidebarMenu: PropTypes.func.isRequired,
user: PropTypes.object,
user: PropTypes.object.isRequired,
}
static defaultProps = {
user: {},
}
componentWillMount() {
console.log('componentWillMount')
shouldComponentUpdate(nextProps) {
return !isEqual(this.props, nextProps)
}
handleNavigate = ({ route, type, props, requireLoggedIn }) => {
const { navigation, user } = this.props
const navigatorApp = navigation.getNavigator('app')
// const navigatorMaster = navigation.getNavigator('master')
const { routeName } = navigatorApp.getCurrentRoute()
// const navigatorApp = navigation.getNavigator('app')
// // const navigatorMaster = navigation.getNavigator('master')
// const { routeName } = navigatorApp.getCurrentRoute()
this.props.closeSidebarMenu()
if (routeName === route) {
// Do nothing
} else if (requireLoggedIn && !user) {
// if (routeName === route) {
// // Do nothing
// } else
if (requireLoggedIn && !user) {
// navigatorMaster.push(Router.getRoute('Login', { redirect: route }))
console.log('Show login')
} else if (type === 'push') {
......@@ -55,19 +53,19 @@ function enhanceSidebarMenu(ComposedComponent) {
render() {
return (
<ComposedComponent {...this.props} />
<ComposedComponent {...this.props} handleNavigate={this.handleNavigate} />
)
}
}
const mapStateToProps = (state, props) => ({
user: userSelector(state, props).user,
user: userSelector(state, props).user || {},
menuIsOpen: state.sidebarMenu.open,
})
const mapDispatchToProps = { openSidebarMenu, closeSidebarMenu }
return connect(mapStateToProps, mapDispatchToProps)(withNavigation(Wrapper))
return connect(mapStateToProps, mapDispatchToProps)(Wrapper)
}
export default enhanceSidebarMenu
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment