@@ -15,70 +15,77 @@ import DialogActions from '@mui/material/DialogActions';
15
15
import DialogContent from '@mui/material/DialogContent' ;
16
16
import DialogContentText from '@mui/material/DialogContentText' ;
17
17
import DialogTitle from '@mui/material/DialogTitle' ;
18
- import NumericInput from 'material-ui-numeric-input' ;
19
18
import { LocalStorage } from '../../LocalStorage/LocalStorage' ;
20
19
21
- export enum ActionType {
22
- ChangeCamera ,
23
- ChangeScene ,
24
- StartLive ,
25
- StopLive ,
26
- ActivateSoundboard
20
+ export enum ReactionType {
21
+ CAMERA_SWITCH = "CAMERA_SWITCH" ,
22
+ SCENE_SWITCH = "SCENE_SWITCH" ,
23
+ START_LIVE = "START_LIVE" ,
24
+ STOP_LIVE = "STOP_LIVE" ,
25
+ TOGGLE_AUDIO_COMPRESSOR = "TOGGLE_AUDIO_COMPRESSOR"
27
26
}
28
27
29
28
export const GeneralActions = ( ) => {
30
29
31
- const keysActionType = Object . keys ( ActionType ) . filter ( k => typeof ActionType [ k as any ] === "number" ) ;
32
- const valuesActionType = keysActionType . map ( k => ActionType [ k as any ] ) ;
33
-
34
- const [ open , setOpen ] = React . useState ( false ) ;
35
- const [ newActionName , setNewActionName ] = React . useState ( "" ) ;
36
- const [ newActionSelected , setNewActionSelected ] = React . useState ( 0 ) ;
37
- const [ newActionParam , setNewActionParam ] = React . useState ( 0 )
38
-
39
- const handleOnChangeSelect = ( action : SelectChangeEvent < unknown > ) => {
40
- const value = action . target . value as ActionType ;
41
- setNewActionSelected ( value ) ;
42
- } ;
43
-
44
- const handleClickOpen = ( ) => {
45
- setOpen ( true ) ;
46
- } ;
47
-
48
- const [ actionsList , setActionsList ] = React . useState ( LocalStorage . getItemObject ( "actionsList" ) || [ ] )
49
-
50
- const handleSave = ( ) => {
51
- console . log ( "newActionName" , newActionName ) ;
52
- console . log ( "newActionSelected" , newActionSelected ) ;
53
- console . log ( "newActionParam" , newActionParam ) ;
54
- if ( newActionName !== "" ) {
55
- let newElem : any = {
56
- id : actionsList . length > 0 ? Math . max ( ...actionsList . map ( ( o : any ) => o . id ) ) + 1 : 1 ,
57
- name : newActionName ,
58
- action : newActionSelected as ActionType ,
30
+ const keysReactionType = Object . keys ( ReactionType ) ;
31
+
32
+ const [ open , setOpen ] = React . useState ( false ) ;
33
+ const [ newActionName , setNewActionName ] = React . useState ( "" ) ;
34
+ const [ newActionSelected , setNewActionSelected ] = React . useState ( "CAMERA_SWITCH" ) ;
35
+ const [ newActionParam , setNewActionParam ] = React . useState ( "" )
36
+
37
+ const handleOnChangeSelect = ( action : SelectChangeEvent < unknown > ) => {
38
+ const value = action . target . value as ReactionType ;
39
+ setNewActionSelected ( value ) ;
40
+ } ;
41
+
42
+ const handleClickOpen = ( ) => {
43
+ setOpen ( true ) ;
44
+ } ;
45
+
46
+ const [ actionsList , setActionsList ] = React . useState ( LocalStorage . getItemObject ( "actionsList" ) || [ ] )
47
+
48
+ const handleSave = ( ) => {
49
+ console . log ( "newActionName" , newActionName ) ;
50
+ console . log ( "newActionSelected" , newActionSelected ) ;
51
+ console . log ( "newActionParam" , newActionParam ) ;
52
+ if ( newActionName !== "" ) {
53
+ let newElem : any = {
54
+ id : actionsList . length > 0 ? Math . max ( ...actionsList . map ( ( o : any ) => o . id ) ) + 1 : 1 ,
55
+ name : newActionName ,
56
+ action : newActionSelected as ReactionType ,
57
+ }
58
+ if ( newActionParam ) {
59
+ if ( newActionSelected === ReactionType . TOGGLE_AUDIO_COMPRESSOR )
60
+ newElem . params = { "audio-source" : newActionParam } ;
61
+ if ( newActionSelected === ReactionType . CAMERA_SWITCH )
62
+ newElem . params = { "video-source" : newActionParam } ;
63
+ if ( newActionSelected === ReactionType . SCENE_SWITCH )
64
+ newElem . params = { "scene-name" : newActionParam } ;
65
+ if ( newActionSelected === ReactionType . START_LIVE )
66
+ newElem . params = { "seconds" : newActionParam } ;
67
+ if ( newActionSelected === ReactionType . STOP_LIVE )
68
+ newElem . params = { "seconds" : newActionParam } ;
69
+ }
70
+
71
+ const newList = actionsList . concat ( [ newElem ] ) ;
72
+
73
+ setActionsList ( newList ) ;
74
+ LocalStorage . setItemObject ( "actionsList" , newList )
75
+ alert ( "Action saved" ) ;
76
+ } else {
77
+ // Put alert
78
+ alert ( "Missing parameters" ) ;
59
79
}
60
- if ( newActionParam ) {
61
- newElem . param_value = newActionParam ;
62
- }
63
-
64
- const newList = actionsList . concat ( [ newElem ] ) ;
65
-
66
- setActionsList ( newList ) ;
67
- LocalStorage . setItemObject ( "actionsList" , newList )
68
- alert ( "Action saved" ) ;
69
- } else {
70
- // Put alert
71
- alert ( "Missing parameters" ) ;
80
+ setNewActionName ( "" ) ;
81
+ setNewActionSelected ( "CAMERA_SWITCH" ) ;
82
+ setNewActionParam ( "" ) ;
83
+ setOpen ( false ) ;
84
+ } ;
85
+
86
+ const handleCancel = ( ) => {
87
+ setOpen ( false ) ;
72
88
}
73
- setNewActionName ( "" ) ;
74
- setNewActionSelected ( 0 ) ;
75
- setNewActionParam ( 0 ) ;
76
- setOpen ( false ) ;
77
- } ;
78
-
79
- const handleCancel = ( ) => {
80
- setOpen ( false ) ;
81
- }
82
89
83
90
84
91
function deleteAction ( id : number ) {
@@ -89,29 +96,29 @@ export const GeneralActions = () => {
89
96
}
90
97
91
98
function getAction ( actionEnum : any ) {
92
- if ( actionEnum === ActionType . ActivateSoundboard )
93
- return "Activate Soundboard " ;
94
- if ( actionEnum === ActionType . ChangeCamera )
99
+ if ( actionEnum === ReactionType . TOGGLE_AUDIO_COMPRESSOR )
100
+ return "Toggle the audio compressor " ;
101
+ if ( actionEnum === ReactionType . CAMERA_SWITCH )
95
102
return "Change the camera"
96
- if ( actionEnum === ActionType . ChangeScene )
103
+ if ( actionEnum === ReactionType . SCENE_SWITCH )
97
104
return "Change the scene"
98
- if ( actionEnum === ActionType . StartLive )
105
+ if ( actionEnum === ReactionType . START_LIVE )
99
106
return "Start the live"
100
- if ( actionEnum === ActionType . StopLive )
107
+ if ( actionEnum === ReactionType . STOP_LIVE )
101
108
return "Stop the live"
102
109
return ""
103
110
}
104
111
105
- function getIcon ( actionEnum : ActionType ) {
106
- if ( actionEnum === ActionType . ActivateSoundboard )
112
+ function getIcon ( actionEnum : ReactionType ) {
113
+ if ( actionEnum === ReactionType . TOGGLE_AUDIO_COMPRESSOR )
107
114
return < AiOutlineSound />
108
- if ( actionEnum === ActionType . ChangeCamera )
115
+ if ( actionEnum === ReactionType . CAMERA_SWITCH )
109
116
return < AiOutlineVideoCamera />
110
- if ( actionEnum === ActionType . ChangeScene )
117
+ if ( actionEnum === ReactionType . SCENE_SWITCH )
111
118
return < MdPanoramaHorizontal />
112
- if ( actionEnum === ActionType . StartLive )
119
+ if ( actionEnum === ReactionType . START_LIVE )
113
120
return < AiOutlinePlayCircle />
114
- if ( actionEnum === ActionType . StopLive )
121
+ if ( actionEnum === ReactionType . STOP_LIVE )
115
122
return < AiOutlineStop />
116
123
return < AiOutlineBug />
117
124
}
@@ -120,7 +127,7 @@ export const GeneralActions = () => {
120
127
< >
121
128
< div className = "container events-container" >
122
129
123
- < h2 > List of Actions </ h2 >
130
+ < h2 > List of Reactions </ h2 >
124
131
125
132
{
126
133
actionsList . length === 0 ? (
@@ -138,7 +145,14 @@ export const GeneralActions = () => {
138
145
{ getAction ( item . action ) }
139
146
</ Typography >
140
147
< Typography variant = "body2" >
141
- { item . param_value ? "Parameter:" + item . param_value : "" }
148
+ {
149
+ item . params ?
150
+ Object . keys ( item . params ) . map ( key => {
151
+ return `${ key } : ${ item . params [ key ] } ` ;
152
+ } ) . join ( "\n" )
153
+ :
154
+ ""
155
+ }
142
156
</ Typography >
143
157
</ CardContent >
144
158
< CardActions disableSpacing className = "rightAlignItem" >
@@ -154,7 +168,7 @@ export const GeneralActions = () => {
154
168
</ div >
155
169
156
170
< Dialog open = { open } onClose = { handleCancel } >
157
- < DialogTitle > Add Action </ DialogTitle >
171
+ < DialogTitle > Add Reaction </ DialogTitle >
158
172
< DialogContent >
159
173
< DialogContentText >
160
174
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
@@ -187,22 +201,20 @@ export const GeneralActions = () => {
187
201
label = "Action"
188
202
>
189
203
{
190
- keysActionType . map ( ( k ) => {
191
- return ( < MenuItem key = { ActionType [ k as any ] } value = { ActionType [ k as any ] } > { getAction ( ActionType [ k as any ] ) } </ MenuItem > )
204
+ keysReactionType . map ( ( k ) => {
205
+ return ( < MenuItem key = { k } value = { k } > { getAction ( k ) } </ MenuItem > )
192
206
} )
193
207
}
194
208
</ Select >
195
209
</ div >
196
210
197
211
< div className = "form-item" >
198
- < NumericInput
199
- name = 'Parameter action'
200
- precision = { 0 }
201
- decimalChar = ','
202
- thousandChar = '.'
203
- label = 'Parameter action'
204
- onChange = { ( action ) => setNewActionParam ( action . target . value as number ) }
205
- variant = 'outlined'
212
+ < TextField
213
+ id = "parameter-action"
214
+ label = "Parameter action"
215
+ type = "text"
216
+ variant = "outlined"
217
+ onChange = { ( action ) => setNewActionParam ( action . target . value ) }
206
218
/>
207
219
</ div >
208
220
@@ -216,7 +228,7 @@ export const GeneralActions = () => {
216
228
< div className = "add_button_pos" >
217
229
< Button variant = "contained" className = "add_button" onClick = { handleClickOpen }
218
230
>
219
- Add Action
231
+ Add Reaction
220
232
</ Button >
221
233
</ div >
222
234
</ >
0 commit comments