1
1
import { useEffect , useState } from 'react' ;
2
2
import Head from 'next/head' ;
3
+ import Link from 'next/link' ;
3
4
import {
4
5
CssBaseline ,
6
+ Container ,
5
7
Box ,
8
+ Typography ,
9
+ Stack ,
10
+ Paper ,
6
11
} from '@mui/material' ;
12
+ import { styled } from '@mui/material/styles' ;
7
13
import { User } from '@firebase/auth' ;
14
+ import { ref , onValue , DataSnapshot } from '@firebase/database' ;
8
15
import { AuthProvider } from '@/lib/AuthProvider' ;
9
- import { auth } from '@/lib/firebase' ;
16
+ import { auth , db } from '@/lib/firebase' ;
10
17
import { Signin } from '@/components/admin/signin' ;
11
18
import { Navbar } from '@/components/admin/Navbar' ;
12
19
13
20
const AdminIndexPage = ( ) => {
14
21
const [ currentUser , setCurrentUser ] = useState < User | null > ( null ) ;
22
+ const [ profiles , setProfiles ] = useState < string [ ] > ( [ ] ) ;
15
23
16
24
useEffect ( ( ) => {
17
25
auth . onAuthStateChanged ( ( user ) => {
18
26
setCurrentUser ( user ) ;
19
27
} ) ;
20
28
} ) ;
21
29
30
+ useEffect ( ( ) => {
31
+ onValue ( ref ( db , '/profiles' ) , ( snap : DataSnapshot ) => {
32
+ setProfiles ( Object . keys ( snap . val ( ) ) ) ;
33
+ } ) ;
34
+ } , [ ] ) ;
35
+
36
+ console . log ( profiles ) ;
37
+
22
38
return (
23
39
< >
24
40
< Head >
@@ -36,6 +52,20 @@ const AdminIndexPage = () => {
36
52
overflow : 'hidden' ,
37
53
} } >
38
54
< 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 >
39
69
</ Box >
40
70
</ AuthProvider >
41
71
) : (
0 commit comments