File tree Expand file tree Collapse file tree 5 files changed +26
-16
lines changed Expand file tree Collapse file tree 5 files changed +26
-16
lines changed Original file line number Diff line number Diff line change 11import React , { Component , MouseEvent } from 'react' ;
22import styled from 'styled-components' ;
3- import { ref , set } from '@firebase/database' ;
3+ import { ref , set , onValue } from '@firebase/database' ;
44import { db } from '@/lib/firebase' ;
55import {
66 TextField ,
77 Button ,
88 Typography ,
99} from '@mui/material' ;
1010import type { IFrameWidgetProps } from './types' ;
11+ import { IFrameWidget } from './widget' ;
1112
1213type Props = {
1314 profile : string ;
1415 id : string ;
15- props : IFrameWidgetProps ;
1616} ;
1717
1818const FormGroup = styled . div `
@@ -27,7 +27,7 @@ const FormGroup = styled.div`
2727class IFrameWidgetEditor extends Component < Props , IFrameWidgetProps > {
2828 constructor ( props : Props ) {
2929 super ( props ) ;
30- this . state = this . props . props ;
30+ this . state = IFrameWidgetEditor . defaultProps ;
3131 this . save = this . save . bind ( this ) ;
3232 this . delete = this . delete . bind ( this ) ;
3333 }
@@ -44,6 +44,12 @@ class IFrameWidgetEditor extends Component<Props, IFrameWidgetProps> {
4444 }
4545 }
4646
47+ componentDidMount ( ) {
48+ onValue ( ref ( db , `/profiles/${ this . props . profile } /widgets/${ this . props . id } /props` ) , ( snap ) => {
49+ this . setState ( snap . val ( ) ) ;
50+ } ) ;
51+ }
52+
4753 render ( ) {
4854 return (
4955 < div >
Original file line number Diff line number Diff line change @@ -8,14 +8,13 @@ import {
88} from '@mui/material' ;
99import styled from 'styled-components' ;
1010import { Property } from 'csstype' ;
11- import { ref , set } from '@firebase/database' ;
11+ import { ref , set , onValue } from '@firebase/database' ;
1212import { db } from '@/lib/firebase' ;
1313import type { TextWidgetProps } from '@/components/TextWidget/types' ;
1414
1515type Props = {
1616 profile : string ;
1717 id : string ;
18- props : TextWidgetProps ;
1918} ;
2019
2120const FormGroup = styled . div `
@@ -87,7 +86,7 @@ class Color {
8786class TextWidgetEditor extends Component < Props , TextWidgetProps > {
8887 constructor ( props : Props ) {
8988 super ( props ) ;
90- this . state = this . props . props ;
89+ this . state = TextWidgetEditor . defaultProps ;
9190 this . save = this . save . bind ( this ) ;
9291 this . delete = this . delete . bind ( this ) ;
9392 }
@@ -104,6 +103,12 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
104103 }
105104 }
106105
106+ componentDidMount ( ) {
107+ onValue ( ref ( db , `/profiles/${ this . props . profile } /widgets/${ this . props . id } /props` ) , ( snap ) => {
108+ this . setState ( snap . val ( ) ) ;
109+ } ) ;
110+ }
111+
107112 render ( ) {
108113 return (
109114 < div >
Original file line number Diff line number Diff line change @@ -7,14 +7,13 @@ import {
77 FormControlLabel ,
88 Checkbox ,
99} from '@mui/material' ;
10- import { ref , set } from '@firebase/database' ;
10+ import { ref , set , onValue } from '@firebase/database' ;
1111import { db } from '@/lib/firebase' ;
1212import type { TimeWidgetProps } from './types' ;
1313
1414type Props = {
1515 profile : string ;
1616 id : string ;
17- props : TimeWidgetProps ;
1817} ;
1918
2019const FormGroup = styled . div `
@@ -32,7 +31,7 @@ const FormGroup = styled.div`
3231class TimeWidgetEditor extends Component < Props , TimeWidgetProps > {
3332 constructor ( props : Props ) {
3433 super ( props ) ;
35- this . state = this . props . props ;
34+ this . state = TimeWidgetEditor . defaultProps ;
3635 this . save = this . save . bind ( this ) ;
3736 this . delete = this . delete . bind ( this ) ;
3837 }
@@ -49,6 +48,12 @@ class TimeWidgetEditor extends Component<Props, TimeWidgetProps> {
4948 }
5049 }
5150
51+ componentDidMount ( ) {
52+ onValue ( ref ( db , `/profiles/${ this . props . profile } /widgets/${ this . props . id } /props` ) , ( snap ) => {
53+ this . setState ( snap . val ( ) ) ;
54+ } ) ;
55+ }
56+
5257 render ( ) {
5358 return (
5459 < div >
Original file line number Diff line number Diff line change @@ -64,7 +64,6 @@ const useStyles = makeStyles((theme) => ({
6464
6565type Widget = {
6666 name : string ;
67- props : any ;
6867}
6968
7069type WidgetList = { [ key : string ] : Widget }
@@ -85,7 +84,7 @@ const Widgets = ({ profile }: { profile: string }) => {
8584 Object . keys ( widgets ) . map ( ( id ) => {
8685 const widget : any = widgets [ id ] ;
8786 const Editor = Editors [ widget . name ] ;
88- return < Editor key = { `${ profile } -${ id } ` } id = { id } props = { widget . props } profile = { profile } />
87+ return < Editor key = { `${ profile } -${ id } ` } id = { id } profile = { profile } />
8988 } )
9089 }
9190 </ div >
Original file line number Diff line number Diff line change @@ -93,7 +93,6 @@ const AdminIndexPage = () => {
9393 const [ userAnchorEl , setUserAnchorEl ] = useState < HTMLElement | null > ( null ) ;
9494 const [ profileAnchorEl , setProfileAnchorEl ] = useState < HTMLElement | null > ( null ) ;
9595 const [ addProfileDialogOpened , setAddProfileDialogOpened ] = useState ( false ) ;
96- const [ currentProfile , setCurrentProfile ] = useState ( 'default' ) ;
9796 const [ profiles , setProfiles ] = useState < string [ ] > ( [ ] ) ;
9897
9998 const isUserMenuOpen = Boolean ( userAnchorEl ) ;
@@ -149,10 +148,6 @@ const AdminIndexPage = () => {
149148 < Typography variant = "h6" className = { classes . title } >
150149 Admin
151150 </ Typography >
152- < Typography variant = "h6" className = { classes . title } >
153- Profile:{ ' ' }
154- { currentProfile }
155- </ Typography >
156151 < Box sx = { { flexGrow : 1 } } />
157152 < Box sx = { { display : { xs : 'none' , md : 'flex' } } } >
158153 < IconButton
You can’t perform that action at this time.
0 commit comments