@@ -6,68 +6,14 @@ import {
66 Container ,
77 Box ,
88} from '@mui/material' ;
9- import { makeStyles } from '@mui/styles'
109import { User } from '@firebase/auth' ;
11- import { ref , onValue , DataSnapshot } from '@firebase/database' ;
1210import { AuthProvider } from '@/lib/AuthProvider' ;
13- import { auth , db } from '@/lib/firebase' ;
11+ import { auth } from '@/lib/firebase' ;
1412import { Signin } from '@/components/admin/signin' ;
15- import { TextWidgetEditor } from '@/components/TextWidget' ;
16- import { TimeWidgetEditor } from '@/components/TimeWidget' ;
17- import { IFrameWidgetEditor } from '@/components/IFrameWidget' ;
1813import { Navbar } from '@/components/admin/Navbar' ;
19-
20- const Editors = {
21- text : TextWidgetEditor ,
22- time : TimeWidgetEditor ,
23- iframe : IFrameWidgetEditor ,
24- } ;
25-
26- const useStyles = makeStyles ( ( _ ) => ( {
27- root : {
28- display : 'flex' ,
29- flexDirection : 'column' ,
30- width : '100%' ,
31- height : '100vh' ,
32- overflow : 'hidden' ,
33- } ,
34- content : {
35- flex : 1 ,
36- overflow : 'auto' ,
37- } ,
38- } ) ) ;
39-
40- type Widget = {
41- name : string ;
42- }
43-
44- type WidgetList = { [ key : string ] : Widget }
45-
46- const Widgets = ( { profile } : { profile : string } ) => {
47- const [ widgets , setWidgets ] = useState < WidgetList > ( { } ) ;
48-
49- useEffect ( ( ) => {
50- const widgetsRef = ref ( db , `/profiles/${ profile } /widgets` ) ;
51- onValue ( widgetsRef , ( snap : DataSnapshot ) => {
52- setWidgets ( snap . val ( ) || { } ) ;
53- } ) ;
54- } , [ profile ] ) ;
55-
56- return (
57- < div >
58- {
59- Object . keys ( widgets ) . map ( ( id ) => {
60- const widget : any = widgets [ id ] ;
61- const Editor = Editors [ widget . name ] ;
62- return < Editor key = { `${ profile } -${ id } ` } id = { id } profile = { profile } />
63- } )
64- }
65- </ div >
66- ) ;
67- } ;
14+ import { Editors } from '@/components/admin/Editors' ;
6815
6916const AdminIndexPage = ( ) => {
70- const classes = useStyles ( ) ;
7117 const router = useRouter ( ) ;
7218 const [ currentUser , setCurrentUser ] = useState < User | null > ( null ) ;
7319
@@ -88,14 +34,20 @@ const AdminIndexPage = () => {
8834 currentUser !== null ? (
8935 < AuthProvider >
9036 < CssBaseline />
91- < div className = { classes . root } >
37+ < Box sx = { {
38+ display : 'flex' ,
39+ flexDirection : 'column' ,
40+ width : '100%' ,
41+ height : '100vh' ,
42+ overflow : 'hidden' ,
43+ } } >
9244 < Navbar profile = { currentProfile } />
93- < Container className = { classes . content } >
45+ < Container sx = { { flex : 1 , overflow : 'auto' } } >
9446 < Box my = { 4 } >
95- < Widgets profile = { currentProfile } />
47+ < Editors profile = { currentProfile } />
9648 </ Box >
9749 </ Container >
98- </ div >
50+ </ Box >
9951 </ AuthProvider >
10052 ) : (
10153 < Signin />
0 commit comments