File tree Expand file tree Collapse file tree 10 files changed +48
-56
lines changed Expand file tree Collapse file tree 10 files changed +48
-56
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
12
12
TextField ,
13
13
MenuItem ,
14
14
} from '@mui/material' ;
15
- import { ref , set , onValue } from '@firebase/database' ;
15
+ import { ref , set } from '@firebase/database' ;
16
16
import { db } from '@/lib/firebase' ;
17
17
import { EditorMap } from '@/components/widgets' ;
18
18
Original file line number Diff line number Diff line change 1
- import { useState , useEffect , MouseEvent } from 'react' ;
1
+ import { useState , useEffect } from 'react' ;
2
2
import {
3
3
Drawer ,
4
4
Toolbar ,
Original file line number Diff line number Diff line change 1
- import { useEffect , useState } from 'react' ;
1
+ import { useState } from 'react' ;
2
2
import { useRouter } from 'next/router' ;
3
3
import styled from 'styled-components' ;
4
4
import { signInWithEmailAndPassword } from '@firebase/auth' ;
Original file line number Diff line number Diff line change 1
- import React , { VFC } from 'react' ;
1
+ import { VFC } from 'react' ;
2
2
import styled from 'styled-components' ;
3
3
4
4
import { SignInForm } from "@/components/admin/SignInForm" ;
Original file line number Diff line number Diff line change 1
- import React , { VFC , CSSProperties } from 'react' ;
1
+ import { VFC , CSSProperties } from 'react' ;
2
2
import type { TextWidgetProps } from './types' ;
3
3
4
4
const calcTextShadow = ( weight , color ) => {
Original file line number Diff line number Diff line change 1
- import React , { CSSProperties } from 'react' ;
1
+ import { Component , CSSProperties } from 'react' ;
2
2
import type { TimeWidgetProps } from './types' ;
3
3
4
4
interface TimeWidgetState {
5
5
time : Date ;
6
6
} ;
7
7
8
- class TimeWidget extends React . Component < TimeWidgetProps , TimeWidgetState > {
8
+ class TimeWidget extends Component < TimeWidgetProps , TimeWidgetState > {
9
9
interval : NodeJS . Timer | null ;
10
10
11
11
constructor ( props : TimeWidgetProps ) {
Original file line number Diff line number Diff line change 8
8
} from '@mui/material' ;
9
9
import { User } from '@firebase/auth' ;
10
10
import { AuthProvider } from '@/lib/AuthProvider' ;
11
- import { auth , db } from '@/lib/firebase' ;
11
+ import { auth } 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' ;
Original file line number Diff line number Diff line change 7
7
Box ,
8
8
Typography ,
9
9
Stack ,
10
- Paper ,
11
10
} from '@mui/material' ;
12
- import { styled } from '@mui/material/styles' ;
13
11
import { User } from '@firebase/auth' ;
14
12
import { ref , onValue , DataSnapshot } from '@firebase/database' ;
15
13
import { AuthProvider } from '@/lib/AuthProvider' ;
Original file line number Diff line number Diff line change
1
+ import { useEffect , useState } from 'react' ;
1
2
import Head from 'next/head' ;
2
3
import { useRouter } from 'next/router' ;
4
+ import { ref , onValue , DataSnapshot } from '@firebase/database' ;
3
5
4
- import { Preview } from '@/components/Preview' ;
6
+ import { db } from '@/lib/firebase' ;
7
+ import { PreviewMap } from '@/components/widgets' ;
8
+
9
+ type Widget = {
10
+ name : string ;
11
+ props : any ;
12
+ }
13
+
14
+ type WidgetList = { [ key : string ] : Widget }
15
+
16
+ type PreviewProps = {
17
+ profile : string ;
18
+ }
19
+
20
+ const Preview = ( { profile } : PreviewProps ) => {
21
+ const [ widgets , setWidgets ] = useState < WidgetList > ( { } ) ;
22
+
23
+ useEffect ( ( ) => {
24
+ const widgetsRef = ref ( db , `/profiles/${ profile } /widgets` ) ;
25
+ onValue ( widgetsRef , ( snap : DataSnapshot ) => {
26
+ if ( snap ?. val ( ) ) {
27
+ setWidgets ( snap . val ( ) ) ;
28
+ }
29
+ } ) ;
30
+ } , [ profile ] ) ;
31
+
32
+ return (
33
+ < div >
34
+ {
35
+ Object . keys ( widgets ) . map ( ( id ) => {
36
+ const widget : any = widgets [ id ] ;
37
+ const Widget = PreviewMap [ widget . name ] ;
38
+ return < Widget key = { id } { ...widget . props } />
39
+ } )
40
+ }
41
+ </ div >
42
+ ) ;
43
+ } ;
5
44
6
45
const PreviewPage = ( ) => {
7
46
const router = useRouter ( ) ;
You can’t perform that action at this time.
0 commit comments