Skip to content

Commit 37815e4

Browse files
committed
Implement menu state as provider
1 parent 9abf6eb commit 37815e4

File tree

6 files changed

+20
-25
lines changed

6 files changed

+20
-25
lines changed

packages/bootstrap-shell/cra-template-bs/template/src/config/config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ const config = {
3434
},
3535
menu: {
3636
width: 240,
37-
offlineIndicatorHeight: 12,
38-
initialAuthMenuOpen: false,
39-
initialMiniMode: false,
40-
initialMenuOpen: true,
4137
initialMobileMenuOpen: false,
4238
initialMiniSwitchVisibility: true,
4339
MenuRight: lazy(() => import('../components/Menu/MenuRight')),

packages/bootstrap-shell/cra-template-bs/template/src/pages/Home/Home.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import React from 'react'
22
import Page from 'bootstrap-shell/lib/containers/Page/Page'
33

44
export default function Home() {
5-
console.log('Home')
5+
66
return (
7-
<Page>
8-
<div>Hallo</div>
9-
</Page>
7+
<div>Hallo</div>
108
)
119
}

packages/bootstrap-shell/src/components/Menu/Menu.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import React from 'react'
22
import { useConfig } from 'base-shell/lib/providers/Config'
33
import * as BS from 'react-bootstrap'
4-
//import RMWLogo from "../../assets/rmw.svg";
4+
import RMWLogo from "../../assets/rmw.svg";
55
import { useMenu } from 'bootstrap-shell/lib/providers/Menu'
6-
//import { GiHamburgerMenu } from 'react-icons/gi'
6+
import { SET_IS_MOBILE_MENU_OPEN } from "bootstrap-shell/lib/providers/Menu/store/types";
7+
import { GiHamburgerMenu } from 'react-icons/gi'
78

89
const Menu = ({ brand }) => {
910
const { appConfig } = useConfig()
1011
const { routes } = appConfig || {}
1112
const { menu } = appConfig || {}
1213
const { globalBrand, MenuRight } = menu || {}
13-
const menuContext = useMenu()
14+
const menuContext = useMenu();
15+
const { DISPATCH_ACTION, isMobileMenuOpen } = menuContext;
1416

15-
console.log('menucontext', menuContext)
16-
17-
// Replace with Provider
18-
const [toggleMenu, setToggleMenu] = React.useState(false)
17+
console.log(isMobileMenuOpen)
1918

2019
const _brand = brand ? brand : globalBrand
2120

@@ -26,7 +25,7 @@ const Menu = ({ brand }) => {
2625
<BS.Col>
2726
<BS.Navbar>
2827
<BS.Navbar.Brand href="#home" className="text-white">
29-
{/*_brand ? _brand : <img src={RMWLogo} alt="RMW Logo" width="40px" />*/}
28+
{brand ? _brand : <img src={RMWLogo} alt="RMW Logo" width="40px" />}
3029
</BS.Navbar.Brand>
3130
<BS.Navbar.Toggle aria-controls="basic-navbar-nav" />
3231
<BS.Navbar.Collapse>
@@ -54,10 +53,10 @@ const Menu = ({ brand }) => {
5453
</BS.Navbar>
5554
{/*Mobile Menu*/}
5655
<BS.Navbar className="d-sm-flex d-md-none d-lg-none justify-content-end">
57-
{/*<GiHamburgerMenu
56+
<GiHamburgerMenu
5857
className="text-white d-sm-block d-md-none d-lg-none"
59-
onClick={() => setToggleMenu(!toggleMenu)}
60-
/>*/}
58+
onClick={() => DISPATCH_ACTION(SET_IS_MOBILE_MENU_OPEN)}
59+
/>
6160
</BS.Navbar>
6261
</BS.Col>
6362
</BS.Container>
@@ -66,7 +65,7 @@ const Menu = ({ brand }) => {
6665
<BS.Col
6766
className="top-0 float-right bg-dark p-2 overflow-hidden"
6867
style={{
69-
maxHeight: toggleMenu ? 1000 : 0,
68+
maxHeight: isMobileMenuOpen ? 1000 : 0,
7069
transition: 'max-height 2s linear',
7170
}}
7271
>

packages/bootstrap-shell/src/containers/LayoutContainer/LayoutContainer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const LayoutContent = ({ children }) => {
1010
<div
1111
style={{
1212
display: 'flex',
13+
flexDirection: 'column'
1314
}}
1415
>
1516
{children}

packages/bootstrap-shell/src/providers/Menu/Provider.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@ import reducer from './store/reducer';
88
import { SET_IS_MOBILE_MENU_OPEN } from './store/types';
99

1010
const Provider = ({ appConfig, children, persistKey = 'menu' }) => {
11-
console.log("Provider");
1211
const { menu } = appConfig || {};
1312
const { initialMobileMenuOpen } = menu;
1413
const savedState = JSON.parse(localStorage.getItem(persistKey))
1514
const [menuStore, dispatch] = useReducer(reducer, {
1615
isMobileMenuOpen: initialMobileMenuOpen,
1716
...savedState,
18-
})
17+
});
1918

2019
const props = {
2120
DISPATCH_ACTION(value, newValue = null) {
2221
if (value === SET_IS_MOBILE_MENU_OPEN) {
23-
dispatch(setIsMobileMenuOpen(newValue !== null ? newValue : !menuStore.isMobileMenuOpen));
22+
console.log("provider", !menuStore.isMobileMenuOpen)
23+
dispatch(setIsMobileMenuOpen(!menuStore.isMobileMenuOpen));
24+
console.log("menustore", menuStore)
2425
}
2526
},
2627

2728
// getters
28-
isMobileMenuOpen: menuStore.setIsMobileMenuOpen,
29+
isMobileMenuOpen: menuStore.isMobileMenuOpen,
2930
}
3031

3132
useEffect(() => {

packages/bootstrap-shell/src/providers/Menu/store/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default function reducer(state = {}, action) {
44
const { type, payload } = action
55
switch (type) {
66
case types.SET_IS_MOBILE_MENU_OPEN:
7-
return { ...state, isAuthMenuOpen: payload }
7+
return { ...state, isMobileMenuOpen: payload }
88
default:
99
return state
1010
}

0 commit comments

Comments
 (0)