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 1
1
import React , { Component , MouseEvent } from 'react' ;
2
2
import styled from 'styled-components' ;
3
- import { ref , set } from '@firebase/database' ;
3
+ import { ref , set , onValue } from '@firebase/database' ;
4
4
import { db } from '@/lib/firebase' ;
5
5
import {
6
6
TextField ,
7
7
Button ,
8
8
Typography ,
9
9
} from '@mui/material' ;
10
10
import type { IFrameWidgetProps } from './types' ;
11
+ import { IFrameWidget } from './widget' ;
11
12
12
13
type Props = {
13
14
profile : string ;
14
15
id : string ;
15
- props : IFrameWidgetProps ;
16
16
} ;
17
17
18
18
const FormGroup = styled . div `
@@ -27,7 +27,7 @@ const FormGroup = styled.div`
27
27
class IFrameWidgetEditor extends Component < Props , IFrameWidgetProps > {
28
28
constructor ( props : Props ) {
29
29
super ( props ) ;
30
- this . state = this . props . props ;
30
+ this . state = IFrameWidgetEditor . defaultProps ;
31
31
this . save = this . save . bind ( this ) ;
32
32
this . delete = this . delete . bind ( this ) ;
33
33
}
@@ -44,6 +44,12 @@ class IFrameWidgetEditor extends Component<Props, IFrameWidgetProps> {
44
44
}
45
45
}
46
46
47
+ componentDidMount ( ) {
48
+ onValue ( ref ( db , `/profiles/${ this . props . profile } /widgets/${ this . props . id } /props` ) , ( snap ) => {
49
+ this . setState ( snap . val ( ) ) ;
50
+ } ) ;
51
+ }
52
+
47
53
render ( ) {
48
54
return (
49
55
< div >
Original file line number Diff line number Diff line change @@ -8,14 +8,13 @@ import {
8
8
} from '@mui/material' ;
9
9
import styled from 'styled-components' ;
10
10
import { Property } from 'csstype' ;
11
- import { ref , set } from '@firebase/database' ;
11
+ import { ref , set , onValue } from '@firebase/database' ;
12
12
import { db } from '@/lib/firebase' ;
13
13
import type { TextWidgetProps } from '@/components/TextWidget/types' ;
14
14
15
15
type Props = {
16
16
profile : string ;
17
17
id : string ;
18
- props : TextWidgetProps ;
19
18
} ;
20
19
21
20
const FormGroup = styled . div `
@@ -87,7 +86,7 @@ class Color {
87
86
class TextWidgetEditor extends Component < Props , TextWidgetProps > {
88
87
constructor ( props : Props ) {
89
88
super ( props ) ;
90
- this . state = this . props . props ;
89
+ this . state = TextWidgetEditor . defaultProps ;
91
90
this . save = this . save . bind ( this ) ;
92
91
this . delete = this . delete . bind ( this ) ;
93
92
}
@@ -104,6 +103,12 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
104
103
}
105
104
}
106
105
106
+ componentDidMount ( ) {
107
+ onValue ( ref ( db , `/profiles/${ this . props . profile } /widgets/${ this . props . id } /props` ) , ( snap ) => {
108
+ this . setState ( snap . val ( ) ) ;
109
+ } ) ;
110
+ }
111
+
107
112
render ( ) {
108
113
return (
109
114
< div >
Original file line number Diff line number Diff line change @@ -7,14 +7,13 @@ import {
7
7
FormControlLabel ,
8
8
Checkbox ,
9
9
} from '@mui/material' ;
10
- import { ref , set } from '@firebase/database' ;
10
+ import { ref , set , onValue } from '@firebase/database' ;
11
11
import { db } from '@/lib/firebase' ;
12
12
import type { TimeWidgetProps } from './types' ;
13
13
14
14
type Props = {
15
15
profile : string ;
16
16
id : string ;
17
- props : TimeWidgetProps ;
18
17
} ;
19
18
20
19
const FormGroup = styled . div `
@@ -32,7 +31,7 @@ const FormGroup = styled.div`
32
31
class TimeWidgetEditor extends Component < Props , TimeWidgetProps > {
33
32
constructor ( props : Props ) {
34
33
super ( props ) ;
35
- this . state = this . props . props ;
34
+ this . state = TimeWidgetEditor . defaultProps ;
36
35
this . save = this . save . bind ( this ) ;
37
36
this . delete = this . delete . bind ( this ) ;
38
37
}
@@ -49,6 +48,12 @@ class TimeWidgetEditor extends Component<Props, TimeWidgetProps> {
49
48
}
50
49
}
51
50
51
+ componentDidMount ( ) {
52
+ onValue ( ref ( db , `/profiles/${ this . props . profile } /widgets/${ this . props . id } /props` ) , ( snap ) => {
53
+ this . setState ( snap . val ( ) ) ;
54
+ } ) ;
55
+ }
56
+
52
57
render ( ) {
53
58
return (
54
59
< div >
Original file line number Diff line number Diff line change @@ -64,7 +64,6 @@ const useStyles = makeStyles((theme) => ({
64
64
65
65
type Widget = {
66
66
name : string ;
67
- props : any ;
68
67
}
69
68
70
69
type WidgetList = { [ key : string ] : Widget }
@@ -85,7 +84,7 @@ const Widgets = ({ profile }: { profile: string }) => {
85
84
Object . keys ( widgets ) . map ( ( id ) => {
86
85
const widget : any = widgets [ id ] ;
87
86
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 } />
89
88
} )
90
89
}
91
90
</ div >
Original file line number Diff line number Diff line change @@ -93,7 +93,6 @@ const AdminIndexPage = () => {
93
93
const [ userAnchorEl , setUserAnchorEl ] = useState < HTMLElement | null > ( null ) ;
94
94
const [ profileAnchorEl , setProfileAnchorEl ] = useState < HTMLElement | null > ( null ) ;
95
95
const [ addProfileDialogOpened , setAddProfileDialogOpened ] = useState ( false ) ;
96
- const [ currentProfile , setCurrentProfile ] = useState ( 'default' ) ;
97
96
const [ profiles , setProfiles ] = useState < string [ ] > ( [ ] ) ;
98
97
99
98
const isUserMenuOpen = Boolean ( userAnchorEl ) ;
@@ -149,10 +148,6 @@ const AdminIndexPage = () => {
149
148
< Typography variant = "h6" className = { classes . title } >
150
149
Admin
151
150
</ Typography >
152
- < Typography variant = "h6" className = { classes . title } >
153
- Profile:{ ' ' }
154
- { currentProfile }
155
- </ Typography >
156
151
< Box sx = { { flexGrow : 1 } } />
157
152
< Box sx = { { display : { xs : 'none' , md : 'flex' } } } >
158
153
< IconButton
You can’t perform that action at this time.
0 commit comments