@@ -8,23 +8,39 @@ import {
8
8
} from '@mui/material' ;
9
9
import { User } from '@firebase/auth' ;
10
10
import { AuthProvider } from '@/lib/AuthProvider' ;
11
- import { auth } from '@/lib/firebase' ;
11
+ import { auth , db } from '@/lib/firebase' ;
12
12
import { Signin } from '@/components/admin/signin' ;
13
13
import { Navbar } from '@/components/admin/Navbar' ;
14
14
import { 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
+ }
16
29
17
30
const AdminIndexPage = ( ) => {
18
31
const router = useRouter ( ) ;
19
32
const [ currentUser , setCurrentUser ] = useState < User | null > ( null ) ;
33
+ const [ currentWidget , setCurrentWidget ] = useState < Widget | null > ( null ) ;
20
34
21
35
const currentProfile = router . query . id as string ;
22
36
23
37
useEffect ( ( ) => {
24
38
auth . onAuthStateChanged ( ( user ) => {
25
39
setCurrentUser ( user ) ;
26
40
} ) ;
27
- } ) ;
41
+ } , [ ] ) ;
42
+
43
+ const Editor = currentWidget ? EditorMap [ currentWidget . name ] : null ;
28
44
29
45
return (
30
46
< >
@@ -50,10 +66,15 @@ const AdminIndexPage = () => {
50
66
flexDirection : 'row' ,
51
67
} }
52
68
>
53
- < LeftSideBar profile = { currentProfile } />
69
+ < LeftSideBar
70
+ profile = { currentProfile }
71
+ selectWidget = { ( widget ) => {
72
+ setCurrentWidget ( widget ) ;
73
+ } }
74
+ />
54
75
< Box component = "main" >
55
76
< Container sx = { { pt : 4 , flex : 1 , overflow : 'auto' } } >
56
- < Editors profile = { currentProfile } />
77
+ { currentWidget && < Editor id = { currentWidget . id } profile = { currentProfile } /> }
57
78
</ Container >
58
79
</ Box >
59
80
</ Box >
0 commit comments