/ src / modules / Profile / Profile.reducer.js
Profile.reducer.js
 1  import profileState from '../../common/data/profile'
 2  import reducerUtil from '../../common/utils/reducer'
 3  import { history } from '../../common/redux/store'
 4  
 5  const DESKTOP_NAVIGATE = 'DESKTOP_NAVIGATE'
 6  const MOBILE_NAVIGATE = 'MOBILE_NAVIGATE'
 7  
 8  export const toggleProfileModalAction = dapp => {
 9    const { innerWidth } = window
10    history.push(`/${dapp.trim()}`, dapp)
11    if (innerWidth <= 1024) {
12      return {
13        type: MOBILE_NAVIGATE,
14        payload: dapp,
15      }
16    }
17    return {
18      type: DESKTOP_NAVIGATE,
19      payload: dapp,
20    }
21  }
22  
23  const toggleProfileModal = (state, payload) => {
24    return Object.assign({}, state, {
25      visible: !state.visible,
26      dapp: payload,
27    })
28  }
29  
30  const navigateProfile = (state, payload) => {
31    return Object.assign({}, state, {
32      visible: false,
33      dapp: payload,
34    })
35  }
36  const map = {
37    [DESKTOP_NAVIGATE]: toggleProfileModal,
38    [MOBILE_NAVIGATE]: navigateProfile,
39  }
40  
41  export default reducerUtil(map, profileState)