1
1
import React from 'react' ;
2
- import './GeneralEvent .css' ;
2
+ import './GeneralActions .css' ;
3
3
import Card from '@mui/material/Card' ;
4
4
import CardActions from '@mui/material/CardActions' ;
5
5
import CardContent from '@mui/material/CardContent' ;
@@ -16,80 +16,63 @@ import DialogContent from '@mui/material/DialogContent';
16
16
import DialogContentText from '@mui/material/DialogContentText' ;
17
17
import DialogTitle from '@mui/material/DialogTitle' ;
18
18
import NumericInput from 'material-ui-numeric-input' ;
19
+ import { LocalStorage } from '../../LocalStorage/LocalStorage' ;
19
20
20
- export enum EventType {
21
+ export enum ActionType {
21
22
ChangeCamera ,
22
23
ChangeScene ,
23
24
StartLive ,
24
25
StopLive ,
25
26
ActivateSoundboard
26
27
}
27
28
28
- export const GeneralEvent = ( ) => {
29
+ export const GeneralActions = ( ) => {
29
30
30
- const keysEventType = Object . keys ( EventType ) . filter ( k => typeof EventType [ k as any ] === "number" ) ;
31
- const valuesEventType = keysEventType . map ( k => EventType [ k as any ] ) ;
31
+ const keysActionType = Object . keys ( ActionType ) . filter ( k => typeof ActionType [ k as any ] === "number" ) ;
32
+ const valuesActionType = keysActionType . map ( k => ActionType [ k as any ] ) ;
32
33
33
34
const [ open , setOpen ] = React . useState ( false ) ;
34
- const [ newEventName , setNewEventName ] = React . useState ( "" ) ;
35
- const [ newEventSelected , setNewEventSelected ] = React . useState ( 0 ) ;
36
- const [ newEventParam , setNewEventParam ] = React . useState ( 0 )
35
+ const [ newActionName , setNewActionName ] = React . useState ( "" ) ;
36
+ const [ newActionSelected , setNewActionSelected ] = React . useState ( 0 ) ;
37
+ const [ newActionParam , setNewActionParam ] = React . useState ( 0 )
37
38
38
- const handleOnChangeSelect = ( event : SelectChangeEvent < unknown > ) => {
39
- const value = event . target . value as EventType ;
40
- setNewEventSelected ( value ) ;
39
+ const handleOnChangeSelect = ( action : SelectChangeEvent < unknown > ) => {
40
+ const value = action . target . value as ActionType ;
41
+ setNewActionSelected ( value ) ;
41
42
} ;
42
43
43
44
const handleClickOpen = ( ) => {
44
45
setOpen ( true ) ;
45
46
} ;
46
47
47
- const [ exampleEvents , setExampleEvents ] = React . useState ( [
48
- {
49
- id : 1 ,
50
- name : "Change to camera 2" ,
51
- event : EventType . ChangeCamera ,
52
- param_value : 2
53
- } ,
54
- {
55
- id : 4 ,
56
- name : "Cut the live with 30delay" ,
57
- event : EventType . StopLive ,
58
- param_value : 30
59
- } ,
60
- {
61
- id : 5 ,
62
- name : "LoL Sound" ,
63
- event : EventType . ActivateSoundboard ,
64
- param_value : 8
65
- }
66
- ] )
48
+ const [ actionsList , setActionsList ] = React . useState ( LocalStorage . getItemObject ( "actionsList" ) || [ ] )
67
49
68
50
const handleSave = ( ) => {
69
- console . log ( "newEventName " , newEventName ) ;
70
- console . log ( "newEventSelected " , newEventSelected ) ;
71
- console . log ( "newEventParam " , newEventParam ) ;
72
- if ( newEventName !== "" ) {
51
+ console . log ( "newActionName " , newActionName ) ;
52
+ console . log ( "newActionSelected " , newActionSelected ) ;
53
+ console . log ( "newActionParam " , newActionParam ) ;
54
+ if ( newActionName !== "" ) {
73
55
let newElem : any = {
74
- id : Math . max ( ...exampleEvents . map ( o => o . id ) ) + 1 ,
75
- name : newEventName ,
76
- event : newEventSelected as EventType ,
56
+ id : actionsList . length > 0 ? Math . max ( ...actionsList . map ( ( o : any ) => o . id ) ) + 1 : 1 ,
57
+ name : newActionName ,
58
+ action : newActionSelected as ActionType ,
77
59
}
78
- if ( newEventParam ) {
79
- newElem . param_value = newEventParam ;
60
+ if ( newActionParam ) {
61
+ newElem . param_value = newActionParam ;
80
62
}
81
63
82
- const newList = exampleEvents . concat ( [ newElem ] ) ;
64
+ const newList = actionsList . concat ( [ newElem ] ) ;
83
65
84
- setExampleEvents ( newList ) ;
85
- alert ( "Event saved" ) ;
66
+ setActionsList ( newList ) ;
67
+ LocalStorage . setItemObject ( "actionsList" , newList )
68
+ alert ( "Action saved" ) ;
86
69
} else {
87
70
// Put alert
88
71
alert ( "Missing parameters" ) ;
89
72
}
90
- setNewEventName ( "" ) ;
91
- setNewEventSelected ( 0 ) ;
92
- setNewEventParam ( 0 ) ;
73
+ setNewActionName ( "" ) ;
74
+ setNewActionSelected ( 0 ) ;
75
+ setNewActionParam ( 0 ) ;
93
76
setOpen ( false ) ;
94
77
} ;
95
78
@@ -98,36 +81,37 @@ export const GeneralEvent = () => {
98
81
}
99
82
100
83
101
- function deleteEvent ( id : number ) {
102
- const newList = exampleEvents . filter ( ( item ) => item . id !== id ) ;
84
+ function deleteAction ( id : number ) {
85
+ const newList = actionsList . filter ( ( item : any ) => item . id !== id ) ;
103
86
104
- setExampleEvents ( newList ) ;
87
+ LocalStorage . setItemObject ( "actionsList" , newList )
88
+ setActionsList ( newList ) ;
105
89
}
106
90
107
- function getEvent ( eventEnum : any ) {
108
- if ( eventEnum === EventType . ActivateSoundboard )
91
+ function getAction ( actionEnum : any ) {
92
+ if ( actionEnum === ActionType . ActivateSoundboard )
109
93
return "Activate Soundboard" ;
110
- if ( eventEnum === EventType . ChangeCamera )
94
+ if ( actionEnum === ActionType . ChangeCamera )
111
95
return "Change the camera"
112
- if ( eventEnum === EventType . ChangeScene )
96
+ if ( actionEnum === ActionType . ChangeScene )
113
97
return "Change the scene"
114
- if ( eventEnum === EventType . StartLive )
98
+ if ( actionEnum === ActionType . StartLive )
115
99
return "Start the live"
116
- if ( eventEnum === EventType . StopLive )
100
+ if ( actionEnum === ActionType . StopLive )
117
101
return "Stop the live"
118
102
return ""
119
103
}
120
104
121
- function getIcon ( eventEnum : EventType ) {
122
- if ( eventEnum === EventType . ActivateSoundboard )
105
+ function getIcon ( actionEnum : ActionType ) {
106
+ if ( actionEnum === ActionType . ActivateSoundboard )
123
107
return < AiOutlineSound />
124
- if ( eventEnum === EventType . ChangeCamera )
108
+ if ( actionEnum === ActionType . ChangeCamera )
125
109
return < AiOutlineVideoCamera />
126
- if ( eventEnum === EventType . ChangeScene )
110
+ if ( actionEnum === ActionType . ChangeScene )
127
111
return < MdPanoramaHorizontal />
128
- if ( eventEnum === EventType . StartLive )
112
+ if ( actionEnum === ActionType . StartLive )
129
113
return < AiOutlinePlayCircle />
130
- if ( eventEnum === EventType . StopLive )
114
+ if ( actionEnum === ActionType . StopLive )
131
115
return < AiOutlineStop />
132
116
return < AiOutlineBug />
133
117
}
@@ -136,29 +120,29 @@ export const GeneralEvent = () => {
136
120
< >
137
121
< div className = "container events-container" >
138
122
139
- < h2 > List of Events </ h2 >
123
+ < h2 > List of Actions </ h2 >
140
124
141
125
{
142
- exampleEvents . length === 0 ? (
126
+ actionsList . length === 0 ? (
143
127
< >
144
- < h4 > No events found.</ h4 >
128
+ < h4 > No action found.</ h4 >
145
129
</ >
146
- ) : ( exampleEvents . map ( ( item , index ) => {
130
+ ) : ( actionsList . map ( ( item : any , index : any ) => {
147
131
return (
148
132
< Card key = { index } className = "card-event" sx = { { minWidth : 150 , minHeight : 100 , margin : 2 } } >
149
133
< CardContent >
150
134
< Typography variant = "h5" component = "div" >
151
- { getIcon ( item . event ) } "{ item . name } "
135
+ { getIcon ( item . action ) } "{ item . name } "
152
136
</ Typography >
153
137
< Typography sx = { { mb : 1.5 } } color = "text.secondary" >
154
- { getEvent ( item . event ) }
138
+ { getAction ( item . action ) }
155
139
</ Typography >
156
140
< Typography variant = "body2" >
157
141
{ item . param_value ? "Parameter:" + item . param_value : "" }
158
142
</ Typography >
159
143
</ CardContent >
160
144
< CardActions disableSpacing className = "rightAlignItem" >
161
- < IconButton onClick = { ( ) => deleteEvent ( item . id ) } aria-label = "delete" >
145
+ < IconButton onClick = { ( ) => deleteAction ( item . id ) } aria-label = "delete" >
162
146
< BsTrash />
163
147
</ IconButton >
164
148
</ CardActions >
@@ -170,7 +154,7 @@ export const GeneralEvent = () => {
170
154
</ div >
171
155
172
156
< Dialog open = { open } onClose = { handleCancel } >
173
- < DialogTitle > Add Event </ DialogTitle >
157
+ < DialogTitle > Add Action </ DialogTitle >
174
158
< DialogContent >
175
159
< DialogContentText >
176
160
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
@@ -184,40 +168,40 @@ export const GeneralEvent = () => {
184
168
< TextField
185
169
autoFocus
186
170
id = "name"
187
- label = "Name of the event "
171
+ label = "Name of the action "
188
172
type = "text"
189
- value = { newEventName }
173
+ value = { newActionName }
190
174
variant = "standard"
191
- onChange = { ( newValue ) => setNewEventName ( newValue . target . value ) }
175
+ onChange = { ( newValue ) => setNewActionName ( newValue . target . value ) }
192
176
/>
193
177
</ div >
194
178
195
179
< div className = "form-item" >
196
- < InputLabel id = "select-event-label" > Event </ InputLabel >
180
+ < InputLabel id = "select-event-label" > Action </ InputLabel >
197
181
< Select
198
182
labelId = "select-event-label"
199
183
id = "select-event"
200
- value = { newEventSelected }
184
+ value = { newActionSelected }
201
185
onChange = { handleOnChangeSelect }
202
186
autoWidth
203
- label = "Event "
187
+ label = "Action "
204
188
>
205
189
{
206
- keysEventType . map ( ( k ) => {
207
- return ( < MenuItem key = { EventType [ k as any ] } value = { EventType [ k as any ] } > { getEvent ( EventType [ k as any ] ) } </ MenuItem > )
190
+ keysActionType . map ( ( k ) => {
191
+ return ( < MenuItem key = { ActionType [ k as any ] } value = { ActionType [ k as any ] } > { getAction ( ActionType [ k as any ] ) } </ MenuItem > )
208
192
} )
209
193
}
210
194
</ Select >
211
195
</ div >
212
196
213
197
< div className = "form-item" >
214
198
< NumericInput
215
- name = 'Parameter event '
199
+ name = 'Parameter action '
216
200
precision = { 0 }
217
201
decimalChar = ','
218
202
thousandChar = '.'
219
- label = 'Parameter event '
220
- onChange = { ( event ) => setNewEventParam ( event . target . value as number ) }
203
+ label = 'Parameter action '
204
+ onChange = { ( action ) => setNewActionParam ( action . target . value as number ) }
221
205
variant = 'outlined'
222
206
/>
223
207
</ div >
@@ -232,7 +216,7 @@ export const GeneralEvent = () => {
232
216
< div className = "add_button_pos" >
233
217
< Button variant = "contained" className = "add_button" onClick = { handleClickOpen }
234
218
>
235
- Add Event
219
+ Add Action
236
220
</ Button >
237
221
</ div >
238
222
</ >
0 commit comments