11import { useEffect , useState } from 'react' ;
22import Head from 'next/head' ;
3+ import Link from 'next/link' ;
34import {
45 CssBaseline ,
6+ Container ,
57 Box ,
8+ Typography ,
9+ Stack ,
10+ Paper ,
611} from '@mui/material' ;
12+ import { styled } from '@mui/material/styles' ;
713import { User } from '@firebase/auth' ;
14+ import { ref , onValue , DataSnapshot } from '@firebase/database' ;
815import { AuthProvider } from '@/lib/AuthProvider' ;
9- import { auth } from '@/lib/firebase' ;
16+ import { auth , db } from '@/lib/firebase' ;
1017import { Signin } from '@/components/admin/signin' ;
1118import { Navbar } from '@/components/admin/Navbar' ;
1219
1320const 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