forked from dvdzkwsk/react-redux-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangbin1994
committed
Nov 20, 2016
1 parent
5cacafd
commit 88244e2
Showing
21 changed files
with
163 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Constants | ||
export const FETCH_SUCCESS = 'sider/fetchSuccess' | ||
// Actions | ||
export const fetchSuccess = (data) => ({ | ||
type: FETCH_SUCCESS, | ||
payload: data | ||
}) | ||
|
||
export const fetchData = () => { | ||
return (dispatch, getState) => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
dispatch(fetchSuccess([{ | ||
title: '热力图', | ||
children: [{ | ||
title: '浏览热力图' | ||
}] | ||
}, { | ||
title: 'NavOne', | ||
children: [{ | ||
title: 'item1', | ||
type: 'drop', | ||
children: [{ title: 'option1', type: 'option' }] | ||
}] | ||
}, { | ||
title: 'NavOne', | ||
children: [{ | ||
title: 'item1', | ||
type: 'group', | ||
children: [{ title: 'option1', type: 'option' }] | ||
}, { | ||
title: 'item2', | ||
type: 'group', | ||
children: [{ title: 'option1', type: 'option' }] | ||
}] | ||
}])) | ||
resolve() | ||
}, 200) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Menu, Icon } from 'antd' | ||
import React, { Component } from 'react' | ||
import { fetchData } from './actions' | ||
import { connect } from 'react-redux' | ||
import { bindActionCreators } from 'redux' | ||
import QueueAnim from 'rc-queue-anim' | ||
|
||
const SubMenu = Menu.SubMenu | ||
const MenuItemGroup = Menu.ItemGroup | ||
|
||
class Sider extends Component { | ||
static propTypes = { | ||
fetchData: React.PropTypes.func.isRequired, | ||
siderData: React.PropTypes.array.isRequired | ||
} | ||
|
||
constructor (props) { | ||
super(props) | ||
this.state = { | ||
current: '1' | ||
} | ||
this.handleClick = this.handleClick.bind(this) | ||
} | ||
|
||
componentWillMount () { | ||
this.props.fetchData() | ||
} | ||
|
||
handleClick (e) { | ||
console.log('click ', e) | ||
this.setState({ | ||
current: e.key | ||
}) | ||
} | ||
|
||
render () { | ||
var subTag = 0 | ||
var itemTag = 0 | ||
var optionTag = 0 | ||
return ( | ||
<Menu onClick={this.handleClick} | ||
defaultOpenKeys={['sub0', 'item0']} | ||
selectedKeys={[this.state.current]} | ||
mode='inline' | ||
theme='dark' | ||
> | ||
{this.props.siderData.map((sub, index) => ( | ||
<SubMenu key={'sub' + subTag++} title={<span><Icon type={sub.icon || 'mail'} /> | ||
<span>{sub.title}</span></span>} > | ||
{sub.children && sub.children.map((item, index) => { | ||
if (item.type === 'group') { | ||
return (<MenuItemGroup key={'item' + itemTag++} title={item.title}> | ||
{item.children && item.children.map((option, index) => ( | ||
<Menu.Item key={'option' + optionTag++}>{option.title}</Menu.Item> | ||
))} | ||
</MenuItemGroup>) | ||
} else if (item.type === 'drop') { | ||
return (<SubMenu key={'item' + itemTag++} title={item.title}> | ||
{item.children && item.children.map((option, index) => ( | ||
<Menu.Item key={'option' + optionTag++}>{option.title}</Menu.Item> | ||
))} | ||
</SubMenu>) | ||
} else { | ||
return ( | ||
<Menu.Item key={'option' + optionTag++}>{item.title}</Menu.Item> | ||
) | ||
} | ||
})} | ||
</SubMenu> | ||
))} | ||
</Menu> | ||
) | ||
} | ||
} | ||
|
||
export default connect(state => ({ | ||
siderData: state.siderData | ||
}), dispatch => ({ | ||
...bindActionCreators({ | ||
fetchData | ||
}, dispatch) | ||
}))(Sider) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { FETCH_SUCCESS } from './actions' | ||
|
||
export default function siderReducer (state = [], action) { | ||
switch (action.type) { | ||
case FETCH_SUCCESS: | ||
return [...action.payload] | ||
default: | ||
return state | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/routes/Heatmap/index.js → src/routes/Heatmap-route/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
import { combineReducers } from 'redux' | ||
import locationReducer from './location' | ||
import siderData from '../containers/Sider/reducers' | ||
|
||
export const makeRootReducer = (asyncReducers) => { | ||
return combineReducers({ | ||
location: locationReducer, | ||
...asyncReducers | ||
siderData | ||
}) | ||
} | ||
|
||
export const injectReducer = (store, { key, reducer }) => { | ||
if (Object.hasOwnProperty.call(store.asyncReducers, key)) { | ||
return | ||
} | ||
|
||
store.asyncReducers[key] = reducer | ||
store.replaceReducer(makeRootReducer(store.asyncReducers)) | ||
} | ||
|
||
export default makeRootReducer |