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 {
1212 TextField ,
1313 MenuItem ,
1414} from '@mui/material' ;
15- import { ref , set , onValue } from '@firebase/database' ;
15+ import { ref , set } from '@firebase/database' ;
1616import { db } from '@/lib/firebase' ;
1717import { EditorMap } from '@/components/widgets' ;
1818
Original file line number Diff line number Diff line change 1- import { useState , useEffect , MouseEvent } from 'react' ;
1+ import { useState , useEffect } from 'react' ;
22import {
33 Drawer ,
44 Toolbar ,
Original file line number Diff line number Diff line change 1- import { useEffect , useState } from 'react' ;
1+ import { useState } from 'react' ;
22import { useRouter } from 'next/router' ;
33import styled from 'styled-components' ;
44import { 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' ;
22import styled from 'styled-components' ;
33
44import { 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' ;
22import type { TextWidgetProps } from './types' ;
33
44const 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' ;
22import type { TimeWidgetProps } from './types' ;
33
44interface TimeWidgetState {
55 time : Date ;
66} ;
77
8- class TimeWidget extends React . Component < TimeWidgetProps , TimeWidgetState > {
8+ class TimeWidget extends Component < TimeWidgetProps , TimeWidgetState > {
99 interval : NodeJS . Timer | null ;
1010
1111 constructor ( props : TimeWidgetProps ) {
Original file line number Diff line number Diff line change 88} from '@mui/material' ;
99import { User } from '@firebase/auth' ;
1010import { AuthProvider } from '@/lib/AuthProvider' ;
11- import { auth , db } from '@/lib/firebase' ;
11+ import { auth } from '@/lib/firebase' ;
1212import { Signin } from '@/components/admin/signin' ;
1313import { Navbar } from '@/components/admin/Navbar' ;
1414import { LeftSideBar } from '@/components/admin/LeftSideNav' ;
Original file line number Diff line number Diff line change 77 Box ,
88 Typography ,
99 Stack ,
10- Paper ,
1110} from '@mui/material' ;
12- import { styled } from '@mui/material/styles' ;
1311import { User } from '@firebase/auth' ;
1412import { ref , onValue , DataSnapshot } from '@firebase/database' ;
1513import { AuthProvider } from '@/lib/AuthProvider' ;
Original file line number Diff line number Diff line change 1+ import { useEffect , useState } from 'react' ;
12import Head from 'next/head' ;
23import { useRouter } from 'next/router' ;
4+ import { ref , onValue , DataSnapshot } from '@firebase/database' ;
35
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+ } ;
544
645const PreviewPage = ( ) => {
746 const router = useRouter ( ) ;
You can’t perform that action at this time.
0 commit comments