@@ -8,23 +8,39 @@ import {
88} from '@mui/material' ;
99import { User } from '@firebase/auth' ;
1010import { AuthProvider } from '@/lib/AuthProvider' ;
11- import { auth } from '@/lib/firebase' ;
11+ import { auth , db } from '@/lib/firebase' ;
1212import { Signin } from '@/components/admin/signin' ;
1313import { Navbar } from '@/components/admin/Navbar' ;
1414import { LeftSideBar } from '@/components/admin/LeftSideNav' ;
15- import { Editors } from '@/components/admin/Editors' ;
15+ import { TextWidgetEditor } from '@/components/TextWidget' ;
16+ import { TimeWidgetEditor } from '@/components/TimeWidget' ;
17+ import { IFrameWidgetEditor } from '@/components/IFrameWidget' ;
18+
19+ const EditorMap = {
20+ text : TextWidgetEditor ,
21+ time : TimeWidgetEditor ,
22+ iframe : IFrameWidgetEditor ,
23+ } ;
24+
25+ type Widget = {
26+ name : string ;
27+ id : string ;
28+ }
1629
1730const AdminIndexPage = ( ) => {
1831 const router = useRouter ( ) ;
1932 const [ currentUser , setCurrentUser ] = useState < User | null > ( null ) ;
33+ const [ currentWidget , setCurrentWidget ] = useState < Widget | null > ( null ) ;
2034
2135 const currentProfile = router . query . id as string ;
2236
2337 useEffect ( ( ) => {
2438 auth . onAuthStateChanged ( ( user ) => {
2539 setCurrentUser ( user ) ;
2640 } ) ;
27- } ) ;
41+ } , [ ] ) ;
42+
43+ const Editor = currentWidget ? EditorMap [ currentWidget . name ] : null ;
2844
2945 return (
3046 < >
@@ -50,10 +66,15 @@ const AdminIndexPage = () => {
5066 flexDirection : 'row' ,
5167 } }
5268 >
53- < LeftSideBar profile = { currentProfile } />
69+ < LeftSideBar
70+ profile = { currentProfile }
71+ selectWidget = { ( widget ) => {
72+ setCurrentWidget ( widget ) ;
73+ } }
74+ />
5475 < Box component = "main" >
5576 < Container sx = { { pt : 4 , flex : 1 , overflow : 'auto' } } >
56- < Editors profile = { currentProfile } />
77+ { currentWidget && < Editor id = { currentWidget . id } profile = { currentProfile } /> }
5778 </ Container >
5879 </ Box >
5980 </ Box >
0 commit comments