feat(redux): Added redux property to handle better navigation

This commit is contained in:
Daniel Gonzalez
2020-12-23 19:29:29 -04:00
parent fe723012a4
commit fb389ed464
3 changed files with 60 additions and 8 deletions
+40 -4
View File
@@ -183,6 +183,9 @@ class AdminLTEPage extends React.Component {
_this.hideSplashLoader()
}, 250)
// Add "changeSection" function to redux store
_this.props.setMenuNavigation({ changeTo: _this.changeSection })
}
componentDidUpdate () {
@@ -190,8 +193,10 @@ class AdminLTEPage extends React.Component {
if (_this.menuLoaded && !_this.state.section) {
if (_this.activedItem) {
_this.changeSection(_this.activedItem)
_this.toggleMenuInMobile()
} else {
_this.changeSection(_this.defaultSection)
_this.toggleMenuInMobile()
}
}
@@ -258,7 +263,11 @@ class AdminLTEPage extends React.Component {
// Section change, renders the corresponding component
// to the selected section. each menu item corresponds
// to a section.
changeSection (section) {
changeSection (section, data) {
if (data) {
_this.props.setMenuNavigation({ data })
}
if (!section) return
if (_this.state.section === section) return
_this.activeItemById(section)
_this.setState({
@@ -287,10 +296,24 @@ class AdminLTEPage extends React.Component {
const windowWidth = window.innerWidth
// console.log("Window Width : ",windowWidth)
if (windowWidth > MENU_HIDE_WIDTH) return
// Veryfies if the sideba is open
const sidebarEle = document.getElementsByClassName('main-sidebar')
const style = window.getComputedStyle(sidebarEle[0])
const transform = style.transform // get transform property
// If the transform property has any
// negative property, means that the menu
// is not visible on the screen
if (transform.match('-')) {
// Returns if the menu is already hidden
return
}
const toggleEle = document.getElementsByClassName('sidebar-toggle')
toggleEle[0].click()
} catch (error) {
console.error(error)
// console.error(error)
}
}
@@ -353,7 +376,7 @@ class AdminLTEPage extends React.Component {
return ''
})
)
} catch (err) {}
} catch (err) { }
}
getInvisibleMenuItem () {
@@ -412,6 +435,17 @@ class AdminLTEPage extends React.Component {
console.warn(error)
}
}
// Displays or hides the sidebar
// in the responsive design
toggleMenuInMobile () {
try {
const windowWidth = window.innerWidth
if (windowWidth > MENU_HIDE_WIDTH) return
const toggleEle = document.getElementsByClassName('sidebar-toggle')
toggleEle[0].click()
} catch (error) {}
}
}
// Props prvided by redux
@@ -423,7 +457,9 @@ AdminLTEPage.propTypes = {
setBchWallet: PropTypes.func.isRequired, // set minimal-slp-wallet instance
bchWallet: PropTypes.object, // get minimal-slp-wallet instance
setTokensInfo: PropTypes.func.isRequired, // set tokens info
tokensInfo: PropTypes.array // tokens info
tokensInfo: PropTypes.array, // tokens info,
setMenuNavigation: PropTypes.func.isRequired,
menuNavigation: PropTypes.object
}
export default AdminLTEPage
+4 -3
View File
@@ -9,8 +9,8 @@ const AdminLTE =
// Maps the props that are going to be sended
// to the component connected with Redux
const mapStateToProps = ({ walletInfo, bchBalance, bchWallet, tokensInfo, currentRate }) => {
return { walletInfo, bchBalance, bchWallet, tokensInfo, currentRate }
const mapStateToProps = ({ walletInfo, bchBalance, bchWallet, tokensInfo, currentRate, menuNavigation }) => {
return { walletInfo, bchBalance, bchWallet, tokensInfo, currentRate, menuNavigation }
}
// Send each action of the reducer as props
@@ -20,7 +20,8 @@ const mapDispatchToProps = dispatch => {
setWalletInfo: value => dispatch({ type: 'SET_WALLET_INFO', value }),
updateBalance: value => dispatch({ type: 'UPDATE_BALANCE', value }),
setBchWallet: value => dispatch({ type: 'SET_BCH_WALLET', value }),
setTokensInfo: value => dispatch({ type: 'SET_TOKENS_INFO', value })
setTokensInfo: value => dispatch({ type: 'SET_TOKENS_INFO', value }),
setMenuNavigation: value => dispatch({ type: 'MENU_NAVIGATION', value })
}
}
+16 -1
View File
@@ -56,6 +56,17 @@ const reducer = (state, action) => {
})
}
// Funcionalidad para cambiar entre las diferentes secciones del menu
// Se puede agregar una propiedad "data" con informacion
// que podrán manipular los demas componentes del menu
if (action.type === 'MENU_NAVIGATION') {
return Object.assign({}, state, {
menuNavigation: {
changeTo: action.value.changeTo || state.menuNavigation.changeTo,
data: action.value.data
}
})
}
return state
}
@@ -102,7 +113,11 @@ const initialState = {
bchBalance: { bchBalance: 0, usdBalance: 0 }, // Wallet Balance
bchWallet: instanceWallet(), // minimal-slp-wallet instance
tokensInfo: [],
currentRate: 0
currentRate: 0,
menuNavigation: {
changeTo: () => {},
data: null
}
}
const createStore = () => reduxCreateStore(reducer, initialState)