File tree Expand file tree Collapse file tree 2 files changed +82
-11
lines changed
components/admin/LeftSideNav Expand file tree Collapse file tree 2 files changed +82
-11
lines changed Original file line number Diff line number Diff line change
1
+ import { useState , useEffect , MouseEvent } from 'react' ;
2
+ import {
3
+ Drawer ,
4
+ Toolbar ,
5
+ List ,
6
+ ListItem ,
7
+ ListItemText ,
8
+ Divider ,
9
+ } from '@mui/material' ;
10
+ import { ref , onValue , DataSnapshot } from '@firebase/database' ;
11
+ import { db } from '@/lib/firebase' ;
12
+
13
+ type LeftSideBarProps = {
14
+ profile : string ;
15
+ }
16
+
17
+ const LeftSideBar = ( { profile } : LeftSideBarProps ) => {
18
+ const [ widgets , setWidgets ] = useState < string [ ] > ( [ ] ) ;
19
+
20
+ useEffect ( ( ) => {
21
+ const widgetsRef = ref ( db , `/profiles/${ profile } /widgets` ) ;
22
+ onValue ( widgetsRef , ( snap : DataSnapshot ) => {
23
+ if ( snap ?. val ( ) ) {
24
+ setWidgets ( Object . keys ( snap . val ( ) ) ) ;
25
+ }
26
+ } ) ;
27
+ } , [ ] ) ;
28
+
29
+ const drawerWidth = 160 ;
30
+
31
+ return (
32
+ < Drawer
33
+ sx = { {
34
+ width : drawerWidth ,
35
+ flexShrink : 0 ,
36
+ '& .MuiDrawer-paper' : {
37
+ width : drawerWidth ,
38
+ boxSizing : 'border-box' ,
39
+ }
40
+ } }
41
+ variant = "permanent"
42
+ anchor = "left"
43
+ >
44
+ < Toolbar />
45
+ < Divider />
46
+ < List >
47
+ { widgets . map ( ( widget ) => (
48
+ < ListItem key = { widget } >
49
+ < ListItemText >
50
+ < a href = { `#${ widget } ` } > { widget } </ a >
51
+ </ ListItemText >
52
+ </ ListItem >
53
+ ) ) }
54
+ </ List >
55
+ </ Drawer >
56
+ ) ;
57
+ } ;
58
+
59
+ export { LeftSideBar } ;
Original file line number Diff line number Diff line change @@ -4,13 +4,15 @@ import { useRouter } from 'next/router';
4
4
import {
5
5
CssBaseline ,
6
6
Container ,
7
+ Toolbar ,
7
8
Box ,
8
9
} from '@mui/material' ;
9
10
import { User } from '@firebase/auth' ;
10
11
import { AuthProvider } from '@/lib/AuthProvider' ;
11
12
import { auth } from '@/lib/firebase' ;
12
13
import { Signin } from '@/components/admin/signin' ;
13
14
import { Navbar } from '@/components/admin/Navbar' ;
15
+ import { LeftSideBar } from '@/components/admin/LeftSideNav' ;
14
16
import { Editors } from '@/components/admin/Editors' ;
15
17
16
18
const AdminIndexPage = ( ) => {
@@ -34,19 +36,29 @@ const AdminIndexPage = () => {
34
36
currentUser !== null ? (
35
37
< AuthProvider >
36
38
< CssBaseline />
37
- < Box sx = { {
38
- display : 'flex' ,
39
- flexDirection : 'column' ,
40
- width : '100%' ,
41
- height : '100vh' ,
42
- overflow : 'hidden' ,
43
- } } >
39
+ < Box
40
+ sx = { {
41
+ display : 'flex' ,
42
+ flexDirection : 'column' ,
43
+ width : '100%' ,
44
+ height : '100vh' ,
45
+ overflow : 'hidden' ,
46
+ } }
47
+ >
44
48
< Navbar profile = { currentProfile } />
45
- < Container sx = { { flex : 1 , overflow : 'auto' } } >
46
- < Box my = { 4 } >
47
- < Editors profile = { currentProfile } />
49
+ < Box
50
+ sx = { {
51
+ display : 'flex' ,
52
+ flexDirection : 'row' ,
53
+ } }
54
+ >
55
+ < LeftSideBar profile = { currentProfile } />
56
+ < Box component = "main" >
57
+ < Container sx = { { pt : 4 , flex : 1 , overflow : 'auto' } } >
58
+ < Editors profile = { currentProfile } />
59
+ </ Container >
48
60
</ Box >
49
- </ Container >
61
+ </ Box >
50
62
</ Box >
51
63
</ AuthProvider >
52
64
) : (
You can’t perform that action at this time.
0 commit comments