Skip to content

Commit fb097ba

Browse files
committed
feat: add lfet side nav for jump to widget
1 parent 028b9ea commit fb097ba

File tree

2 files changed

+82
-11
lines changed

2 files changed

+82
-11
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 };

src/pages/admin/[id]/index.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { useRouter } from 'next/router';
44
import {
55
CssBaseline,
66
Container,
7+
Toolbar,
78
Box,
89
} from '@mui/material';
910
import { User } from '@firebase/auth';
1011
import { AuthProvider } from '@/lib/AuthProvider';
1112
import { auth } from '@/lib/firebase';
1213
import { Signin } from '@/components/admin/signin';
1314
import { Navbar } from '@/components/admin/Navbar';
15+
import { LeftSideBar } from '@/components/admin/LeftSideNav';
1416
import { Editors } from '@/components/admin/Editors';
1517

1618
const AdminIndexPage = () => {
@@ -34,19 +36,29 @@ const AdminIndexPage = () => {
3436
currentUser !== null ? (
3537
<AuthProvider>
3638
<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+
>
4448
<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>
4860
</Box>
49-
</Container>
61+
</Box>
5062
</Box>
5163
</AuthProvider>
5264
) : (

0 commit comments

Comments
 (0)