Commit df428d77 authored by Denis Sedura's avatar Denis Sedura

Move Map, SideMenu, Nearby store list

parent f63614f5
{
"extends": "tipsi",
"globals": {
"device": false,
"expect": false,
"waitFor": false,
"element": false,
"by": false,
"describe": false,
"it": false,
"before": false,
}
}
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { loadUserProfile, logout } from 'tipsi_api/actions'
import { cleanReducers } from '../../actions'
const UNAUTHORIZED_ERROR_CODE = 403
function enhanceAppComponent(ComposedComponent) {
class Wrapper extends Component {
static PropTypes = {
loadUserProfile: PropTypes.func.isRequired,
cleanReducers: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired,
}
/* eslint-disable react/prop-types */
async componentDidMount() {
try {
await this.props.loadUserProfile()
} catch ({ statusCode }) {
if (statusCode === UNAUTHORIZED_ERROR_CODE) {
await this.props.logout()
this.props.cleanReducers(['auth'])
}
}
}
render() {
return (
<ComposedComponent {...this.props} />
)
}
}
return connect(null, { loadUserProfile, logout, cleanReducers })(Wrapper)
}
export default enhanceAppComponent
export { default as enhanceAppComponent } from './App'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
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 { updateCurrentLocation } from '../../actions'
import sortStoresByDistance from '../../utils/sortStoresByDistance'
import unimplementedFeature from '../../utils/unimplementedFeature'
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,
}
handlePressSettings = () => (
unimplementedFeature()
)
handleRowPress = (storeId, title) => (
this.props.navigator.push('Store', { storeId, title })
)
handleSubmitEditing = query => (
this.props.navigator.push('Search', { query })
)
handlePressSuggestion = suggestion => (
this.props.navigator.push('Search', { query: suggestion.name })
)
loadStores = () => {
this.props.loadStores()
}
render() {
return (
<ComposedComponent
{...this.props}
handlePressSettings={this.handlePressSettings}
handleRowPress={this.handleRowPress}
handleSubmitEditing={this.handleSubmitEditing}
handlePressSuggestion={this.handlePressSuggestion}
/>
)
}
}
const mapStateToProps = createSelector(
[state => state.currentLocation, storesSelector],
(currentLocation, { stores }) => {
if (!stores) {
return { currentLocation, nearbyStores: [] }
}
const nearbyStores = sortStoresByDistance(stores, currentLocation)
return {
currentLocation,
nearbyStores: nearbyStores || [],
}
}
)
const mapDispatchToProps = { loadStores, updateCurrentLocation }
return connect(mapStateToProps, mapDispatchToProps)(withNavigation(Wrapper))
}
export default enhanceNearbyStoreList
export { default as enhanceNearbyStoreList } from './NearbyStoreList'
export { enhanceAppComponent } from './App'
export { enhanceInitialComponent } from './InitialScreen'
export { enhanceAgeConfirmation } from './AgeConfirmation'
export { enhanceNearbyStoreList } from './NearbyStoreList'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { createSelector } from 'reselect'
import convertCoords from '../../utils/convertCoords'
function enhanceMainLocationMap(ComposedComponent) {
class Wrapper extends Component {
static propTypes = {
currentLocation: PropTypes.object.isRequired,
storeLocations: PropTypes.array.isRequired,
}
render() {
return (
<ComposedComponent {...this.props} />
)
}
}
const mapStateToProps = createSelector(
state => state.currentLocation,
state => state.paginations.nearbyStores,
state => state.entities.stores,
(currentLocation, nearbyStores, stores) => {
const key = `${currentLocation.lat}/${currentLocation.lng}/${currentLocation.radius}`
const { ids } = nearbyStores[key] || { ids: [] }
return {
currentLocation: convertCoords(currentLocation),
storeLocations: ids.map(id => ({
key: id,
markerSize: 'small',
...convertCoords(stores[id]),
})),
}
}
)
return connect(mapStateToProps)(Wrapper)
}
export default enhanceMainLocationMap
export { default as enhanceMainLocationMap } from './MainLocationMap'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { openSidebarMenu } from '../../actions'
function enhanceMenuButton(ComposedComponent) {
class Wrapper extends Component {
static propTypes = {
menuIsOpen: PropTypes.bool.isRequired,
openSidebarMenu: PropTypes.func.isRequired,
}
render() {
return (
<ComposedComponent {...this.props} />
)
}
}
const mapStateToProps = state => ({
menuIsOpen: state.sidebarMenu.open,
})
return connect(mapStateToProps, { openSidebarMenu })(Wrapper)
}
export default enhanceMenuButton
export { default as enhanceMenuButton } from './MenuButton'
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 Router from '../../navigation/Router'
import { openSidebarMenu, closeSidebarMenu } from '../../actions'
function enhanceSidebarMenu(ComposedComponent) {
class Wrapper extends Component {
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,
}
static defaultProps = {
user: {},
}
componentWillMount() {
console.log('componentWillMount')
}
handleNavigate = ({ route, type, props, requireLoggedIn }) => {
const { navigation, user } = this.props
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) {
// navigatorMaster.push(Router.getRoute('Login', { redirect: route }))
console.log('Show login')
} else if (type === 'push') {
// navigatorApp.push(Router.getRoute(route, props))
console.log('Push to ', route)
} else if (type === 'reset') {
// navigatorApp.immediatelyResetStack([Router.getRoute(route, props)])
console.log('Reset stack')
} else if (type === 'popToTop') {
// navigatorApp.popToTop()
// navigatorApp.push(Router.getRoute(route, { ...props, user }))
console.log('Go to top of stack')
} else {
throw new Error(`Wrong navigation type: ${type}`)
}
}
render() {
return (
<ComposedComponent {...this.props} />
)
}
}
const mapStateToProps = (state, props) => ({
user: userSelector(state, props).user,
menuIsOpen: state.sidebarMenu.open,
})
const mapDispatchToProps = { openSidebarMenu, closeSidebarMenu }
return connect(mapStateToProps, mapDispatchToProps)(withNavigation(Wrapper))
}
export default enhanceSidebarMenu
export { default as enhanceSidebarMenu } from './SidebarMenu'
export { enhanceMenuButton } from './MenuButton'
export { enhanceMainLocationMap } from './MainLocationMap'
export { enhanceSidebarMenu } from './SidebarMenu'
export { createRoutes } from './routes'
......@@ -7,25 +7,29 @@
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^3.13.1",
"eslint-config-tipsi": "1.5.0",
"date-fns": "^1.28.1",
"decimal.js-light": "^2.2.4",
"lodash": "^4.17.4",
"prop-types": "^15.5.10",
"react": "16.0.0-alpha.12",
"react-dom": "^16.1.1",
"react-redux": "^5.0.2",
"tipsi-stripe": "4.0.0",
"react-native": "0.48.4",
"react-redux": "^5.0.2",
"react-transition-group": "^2.2.0",
"redux": "^3.6.0",
"redux-logger": "^3.0.6",
"redux-persist": "^4.1.0",
"redux-persist-transform-filter": "0.0.6",
"redux-thunk": "^2.2.0",
"reselect": "^3.0.1",
"prop-types": "^15.5.10",
"decimal.js-light": "^2.2.4",
"date-fns": "^1.28.1"
"tipsi-stripe": "4.0.0"
},
"peerDependencies": {
"@expo/ex-navigation": "3.1.0",
"react-native-firebase-analytics": "3.0.2",
"tipsi_api": "git+ssh://git@git.gettipsi.com/tipsi_frontend/tipsi_api.git#1.30.0"
}
},
"dependencies": {}
}
import { reduce, keys } from 'lodash'
import { enhanceAppComponent } from './Screens/App'
const routesMap = {
home: {
path: '/',
component: enhanceAppComponent,
},
}
export function createRoutes(routes = {}) {
return reduce(keys(routesMap), (result, key) => {
const mappedRoute = routes[key]
if (mappedRoute) {
result[key] = {
...routesMap[key],
...mappedRoute,
component: routesMap[key].component(mappedRoute.component),
}
}
return result
}, {})
}
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { createSelector } from 'reselect'
import { createSearchInventoryListSelector } from 'tipsi_api/selectors'
import { searchInventory, clearPaginationCache } from 'tipsi_api/actions'
import { MAIN_SEARCH_KEY, changeSearchQuery } from '../actions'
const SEARCH_INVENTORY_FIELDS = {
fts: 'id,inventory',
inventory: 'id,wine,drink',
wine: 'id,name',
drink: 'id,name',
}
/* eslint-disable import/prefer-default-export */
export const searchSelector = (component) => {
const searchKeySelector = () => MAIN_SEARCH_KEY
const searchQueriesSelector = createSelector(
state => state.searchQueries,
searchQueries => searchQueries[MAIN_SEARCH_KEY]
)
const mapStateToProps = createSelector(
createSearchInventoryListSelector(searchKeySelector),
searchQueriesSelector,
({ result, isLoading }, searchPageQuery) => ({
result: result.map(({ inventory }) => ({
id: inventory.id,
name: inventory.wine ? inventory.wine.name : inventory.drink.name,
detailsType: 'inventory',
itemType: inventory.wine ? 'wine' : 'drink',
})),
isLoading,
searchPageQuery,
})
)
const mapDispatchToProps = dispatch => (
bindActionCreators({
search: params => searchInventory({
...params,
key: MAIN_SEARCH_KEY,
fields: SEARCH_INVENTORY_FIELDS,
}),
clearPaginationCache: () => clearPaginationCache({ searchInventory: MAIN_SEARCH_KEY }),
changeSearchQuery: params => changeSearchQuery({ ...params, key: MAIN_SEARCH_KEY }),
}, dispatch)
)
return connect(mapStateToProps, mapDispatchToProps)(component)
}
......@@ -7,6 +7,7 @@ import uuidv4 from 'uuid/v4'
import { createNavigationEnabledStore, NavigationReducer as navigation } from '@expo/ex-navigation'
import { entities, relations, auth, checkApi, meta, paginations } from 'tipsi_api/reducers'
import createApiMiddleware from 'tipsi_api/middleware'
import logger from 'redux-logger'
import createCleanableReducer from './reducers/createCleanableReducer'
import * as reducers from './reducers'
import { analyticsMiddleware } from './middlewares'
......@@ -26,7 +27,7 @@ const tipsiMiddleware = createApiMiddleware({
}),
})
const middleware = [tipsiMiddleware, thunk, analyticsMiddleware]
const middleware = [tipsiMiddleware, thunk, analyticsMiddleware]//, logger]
// if (__DEV__) {
// middleware.push(require('redux-logger')())
......@@ -62,9 +63,9 @@ export const persistorRehydration = new Promise((resolve) => {
'userCards',
'userAddresses',
'userDelivery',
// 'ageConfirmation',
'ageConfirmation',
],
blacklist: ['navigation', 'ageConfirmation'],
blacklist: ['navigation'],
transforms: [
createFilter('entities', ['mobileUsers', 'mobileProfiles']),
],
......
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