1- import { Trans } from "@lingui/macro" ;
2- import { useState } from "preact/hooks" ;
3-
41import { plugins } from "../../config" ;
52import style from "./style.less" ;
63
74export const Menu = ( { opened, toggle } ) => {
8- const [ currentView , setCurrentView ] = useState ( "node" ) ;
9- const hasCommunityPlugins = ( ) =>
10- plugins . filter ( ( p ) => p . menuView && p . menuView === "community" ) . length >
11- 0 ;
12- function changeCurrentView ( e ) {
13- e . preventDefault ( ) ;
14- setCurrentView ( currentView === "node" ? "community" : "node" ) ;
15- }
5+ // Group plugins by menuGroup
6+ const groupedPlugins = plugins
7+ . filter ( ( plugin ) => plugin . page && plugin . menu ) // Only include plugins with both `page` and `menu`
8+ . reduce ( ( groups , plugin ) => {
9+ const group = plugin . menuGroup || "default" ; // Use "default" for plugins without a menuGroup
10+ if ( ! groups [ group ] ) {
11+ groups [ group ] = [ ] ;
12+ }
13+ groups [ group ] . push ( plugin . menu ) ;
14+ return groups ;
15+ } , { } ) ;
1616
1717 return (
1818 < div
@@ -21,38 +21,15 @@ export const Menu = ({ opened, toggle }) => {
2121 } d-flex flex-column`}
2222 >
2323 < nav className = { style . menuItemsWrapper } onClick = { toggle } >
24- { plugins
25- . map ( ( plugin ) => ( {
26- ...plugin ,
27- menuView : plugin . menuView || "node" ,
28- } ) )
29- . filter (
30- ( plugin ) =>
31- plugin . page &&
32- plugin . menu &&
33- plugin . menuView === currentView
34- )
35- . map ( ( plugin ) => plugin . menu )
36- . map ( ( Component , index ) => (
37- < Component key = { index } />
38- ) ) }
24+ { Object . entries ( groupedPlugins ) . map ( ( [ group , components ] ) => (
25+ < div key = { group } className = { style . menuGroup } >
26+ { group !== "default" && < hr /> }
27+ { components . map ( ( Component , index ) => (
28+ < Component key = { index } />
29+ ) ) }
30+ </ div >
31+ ) ) }
3932 </ nav >
40- { hasCommunityPlugins ( ) && (
41- < nav className = { style . viewSwitchWrapper } >
42- < a
43- href = "#0"
44- className = { style . viewSwitch }
45- onClick = { changeCurrentView }
46- >
47- { currentView === "node" && (
48- < Trans > Go to Community View</ Trans >
49- ) }
50- { currentView === "community" && (
51- < Trans > Go to Node View</ Trans >
52- ) }
53- </ a >
54- </ nav >
55- ) }
5633 </ div >
5734 ) ;
5835} ;
0 commit comments