Skip to content

Commit c9bd540

Browse files
authored
feat: display profile links on admin top (#121)
1 parent 2fe227a commit c9bd540

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/pages/admin/index.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
import { useEffect, useState } from 'react';
22
import Head from 'next/head';
3+
import Link from 'next/link';
34
import {
45
CssBaseline,
6+
Container,
57
Box,
8+
Typography,
9+
Stack,
10+
Paper,
611
} from '@mui/material';
12+
import { styled } from '@mui/material/styles';
713
import { User } from '@firebase/auth';
14+
import { ref, onValue, DataSnapshot } from '@firebase/database';
815
import { AuthProvider } from '@/lib/AuthProvider';
9-
import { auth } from '@/lib/firebase';
16+
import { auth, db } from '@/lib/firebase';
1017
import { Signin } from '@/components/admin/signin';
1118
import { Navbar } from '@/components/admin/Navbar';
1219

1320
const AdminIndexPage = () => {
1421
const [currentUser, setCurrentUser] = useState<User | null>(null);
22+
const [profiles, setProfiles] = useState<string[]>([]);
1523

1624
useEffect(() => {
1725
auth.onAuthStateChanged((user) => {
1826
setCurrentUser(user);
1927
});
2028
});
2129

30+
useEffect(() => {
31+
onValue(ref(db, '/profiles'), (snap: DataSnapshot) => {
32+
setProfiles(Object.keys(snap.val()));
33+
});
34+
}, []);
35+
36+
console.log(profiles);
37+
2238
return (
2339
<>
2440
<Head>
@@ -36,6 +52,20 @@ const AdminIndexPage = () => {
3652
overflow: 'hidden',
3753
}}>
3854
<Navbar />
55+
<Container sx={{ flex: 1, overflow: 'auto' }}>
56+
<div>
57+
<Typography variant="h4" component="h2" sx={{ mt: 4 }}>Profiles</Typography>
58+
<Box sx={{ mt: 4, display: 'flex' }}>
59+
<Box>
60+
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={{ xs:1, sm: 2, md: 4}}>
61+
{profiles.map((profile) => (
62+
<Link key={profile} href={`/admin/${profile}`}>{profile}</Link>
63+
))}
64+
</Stack>
65+
</Box>
66+
</Box>
67+
</div>
68+
</Container>
3969
</Box>
4070
</AuthProvider>
4171
) : (

0 commit comments

Comments
 (0)