Skip to content

Commit cee0f87

Browse files
authored
Rework Word Detection + Generate Action (#8)
* feat(): add babel-eslint to help IDE * feat(localstorage): create Generic class * fix(Actions): save locally list of actions rename + rename event to action ! * feat(LocalStorage): 100% coverage * feat(Word Detection): add Actions + save Events * fix(): update sidebar Audio part Video part Action part * fix(test): remove unupdated tests
1 parent f9a8427 commit cee0f87

File tree

19 files changed

+348
-288
lines changed

19 files changed

+348
-288
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@types/react-dom": "^16.9.8",
2626
"@types/react-ranger": "^2.0.1",
2727
"@types/styled-components": "^5.1.17",
28+
"babel-eslint": "^10.1.0",
2829
"concurrently": "^5.2.0",
2930
"electron-is-dev": "^1.2.0",
3031
"electron-renderer": "^2.0.4",
@@ -61,6 +62,7 @@
6162
"publish": "electron-forge publish",
6263
"build": "yarn react-build && npm run electron-build",
6364
"test": "react-scripts test",
65+
"test-coverage": "react-scripts test --coverage",
6466
"compile": "electron-webpack",
6567
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null",
6668
"eject": "react-scripts eject",
File renamed without changes.

src/Components/Events/GeneralEvent.tsx renamed to src/Components/Actions/GeneralActions.tsx

Lines changed: 65 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import './GeneralEvent.css';
2+
import './GeneralActions.css';
33
import Card from '@mui/material/Card';
44
import CardActions from '@mui/material/CardActions';
55
import CardContent from '@mui/material/CardContent';
@@ -16,80 +16,63 @@ import DialogContent from '@mui/material/DialogContent';
1616
import DialogContentText from '@mui/material/DialogContentText';
1717
import DialogTitle from '@mui/material/DialogTitle';
1818
import NumericInput from 'material-ui-numeric-input';
19+
import { LocalStorage } from '../../LocalStorage/LocalStorage';
1920

20-
export enum EventType {
21+
export enum ActionType {
2122
ChangeCamera,
2223
ChangeScene,
2324
StartLive,
2425
StopLive,
2526
ActivateSoundboard
2627
}
2728

28-
export const GeneralEvent = () => {
29+
export const GeneralActions = () => {
2930

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]);
3233

3334
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)
3738

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);
4142
};
4243

4344
const handleClickOpen = () => {
4445
setOpen(true);
4546
};
4647

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") || [])
6749

6850
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 !== "") {
7355
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,
7759
}
78-
if (newEventParam) {
79-
newElem.param_value = newEventParam;
60+
if (newActionParam) {
61+
newElem.param_value = newActionParam;
8062
}
8163

82-
const newList = exampleEvents.concat([newElem]);
64+
const newList = actionsList.concat([newElem]);
8365

84-
setExampleEvents(newList);
85-
alert("Event saved");
66+
setActionsList(newList);
67+
LocalStorage.setItemObject("actionsList", newList)
68+
alert("Action saved");
8669
} else {
8770
// Put alert
8871
alert("Missing parameters");
8972
}
90-
setNewEventName("");
91-
setNewEventSelected(0);
92-
setNewEventParam(0);
73+
setNewActionName("");
74+
setNewActionSelected(0);
75+
setNewActionParam(0);
9376
setOpen(false);
9477
};
9578

@@ -98,36 +81,37 @@ export const GeneralEvent = () => {
9881
}
9982

10083

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);
10386

104-
setExampleEvents(newList);
87+
LocalStorage.setItemObject("actionsList", newList)
88+
setActionsList(newList);
10589
}
10690

107-
function getEvent(eventEnum: any) {
108-
if (eventEnum === EventType.ActivateSoundboard)
91+
function getAction(actionEnum: any) {
92+
if (actionEnum === ActionType.ActivateSoundboard)
10993
return "Activate Soundboard";
110-
if (eventEnum === EventType.ChangeCamera)
94+
if (actionEnum === ActionType.ChangeCamera)
11195
return "Change the camera"
112-
if (eventEnum === EventType.ChangeScene)
96+
if (actionEnum === ActionType.ChangeScene)
11397
return "Change the scene"
114-
if (eventEnum === EventType.StartLive)
98+
if (actionEnum === ActionType.StartLive)
11599
return "Start the live"
116-
if (eventEnum === EventType.StopLive)
100+
if (actionEnum === ActionType.StopLive)
117101
return "Stop the live"
118102
return ""
119103
}
120104

121-
function getIcon(eventEnum: EventType) {
122-
if (eventEnum === EventType.ActivateSoundboard)
105+
function getIcon(actionEnum: ActionType) {
106+
if (actionEnum === ActionType.ActivateSoundboard)
123107
return <AiOutlineSound />
124-
if (eventEnum === EventType.ChangeCamera)
108+
if (actionEnum === ActionType.ChangeCamera)
125109
return <AiOutlineVideoCamera />
126-
if (eventEnum === EventType.ChangeScene)
110+
if (actionEnum === ActionType.ChangeScene)
127111
return <MdPanoramaHorizontal />
128-
if (eventEnum === EventType.StartLive)
112+
if (actionEnum === ActionType.StartLive)
129113
return <AiOutlinePlayCircle />
130-
if (eventEnum === EventType.StopLive)
114+
if (actionEnum === ActionType.StopLive)
131115
return <AiOutlineStop />
132116
return <AiOutlineBug />
133117
}
@@ -136,29 +120,29 @@ export const GeneralEvent = () => {
136120
<>
137121
<div className="container events-container">
138122

139-
<h2>List of Events</h2>
123+
<h2>List of Actions</h2>
140124

141125
{
142-
exampleEvents.length === 0 ? (
126+
actionsList.length === 0 ? (
143127
<>
144-
<h4>No events found.</h4>
128+
<h4>No action found.</h4>
145129
</>
146-
) : (exampleEvents.map((item, index) => {
130+
) : (actionsList.map((item: any, index: any) => {
147131
return (
148132
<Card key={index} className="card-event" sx={{ minWidth: 150, minHeight: 100, margin: 2 }}>
149133
<CardContent>
150134
<Typography variant="h5" component="div">
151-
{ getIcon(item.event) } "{ item.name }"
135+
{ getIcon(item.action) } "{ item.name }"
152136
</Typography>
153137
<Typography sx={{ mb: 1.5 }} color="text.secondary">
154-
{ getEvent(item.event) }
138+
{ getAction(item.action) }
155139
</Typography>
156140
<Typography variant="body2">
157141
{ item.param_value ? "Parameter:" + item.param_value : "" }
158142
</Typography>
159143
</CardContent>
160144
<CardActions disableSpacing className="rightAlignItem">
161-
<IconButton onClick={() => deleteEvent(item.id)} aria-label="delete">
145+
<IconButton onClick={() => deleteAction(item.id)} aria-label="delete">
162146
<BsTrash />
163147
</IconButton>
164148
</CardActions>
@@ -170,7 +154,7 @@ export const GeneralEvent = () => {
170154
</div>
171155

172156
<Dialog open={open} onClose={handleCancel}>
173-
<DialogTitle>Add Event</DialogTitle>
157+
<DialogTitle>Add Action</DialogTitle>
174158
<DialogContent>
175159
<DialogContentText>
176160
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
@@ -184,40 +168,40 @@ export const GeneralEvent = () => {
184168
<TextField
185169
autoFocus
186170
id="name"
187-
label="Name of the event"
171+
label="Name of the action"
188172
type="text"
189-
value={newEventName}
173+
value={newActionName}
190174
variant="standard"
191-
onChange={(newValue) => setNewEventName(newValue.target.value)}
175+
onChange={(newValue) => setNewActionName(newValue.target.value)}
192176
/>
193177
</div>
194178

195179
<div className="form-item">
196-
<InputLabel id="select-event-label">Event</InputLabel>
180+
<InputLabel id="select-event-label">Action</InputLabel>
197181
<Select
198182
labelId="select-event-label"
199183
id="select-event"
200-
value={newEventSelected}
184+
value={newActionSelected}
201185
onChange={handleOnChangeSelect}
202186
autoWidth
203-
label="Event"
187+
label="Action"
204188
>
205189
{
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>)
208192
})
209193
}
210194
</Select>
211195
</div>
212196

213197
<div className="form-item">
214198
<NumericInput
215-
name='Parameter event'
199+
name='Parameter action'
216200
precision={0}
217201
decimalChar=','
218202
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)}
221205
variant='outlined'
222206
/>
223207
</div>
@@ -232,7 +216,7 @@ export const GeneralEvent = () => {
232216
<div className="add_button_pos">
233217
<Button variant="contained" className="add_button" onClick={handleClickOpen}
234218
>
235-
Add Event
219+
Add Action
236220
</Button>
237221
</div>
238222
</>

src/Components/AddNewWord/AddNewWord.tsx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ export const AddNewWord = (props: any) => {
4646
const handleClose = () => setOpen(false);
4747

4848
const save = () => {
49-
if (props.newEvent.keywords.length != 0) {
49+
if (props.newEvent.keywords.length !== 0 && props.newEvent.source && props.newEvent.source.name) {
5050
props.addNewEvent(props.newEvent);
51+
handleClose();
5152
} else {
52-
props.setnewEvent({ id: props.newEvent, keywords: [], sources: [] });
53+
alert("Please insert at least one keyword and one source.")
5354
}
54-
handleClose();
5555
};
5656

5757
const closeWithoutSave = () => {
@@ -60,7 +60,7 @@ export const AddNewWord = (props: any) => {
6060
};
6161

6262
const handleChange = (e: any) => {
63-
if (e.key === "Enter" && e.currentTarget.value != "") {
63+
if (e.key === "Enter" && e.currentTarget.value !== "") {
6464
if (props.newEvent.keywords.length >= 10) {
6565
e.currentTarget.value = ""
6666
alert("You cannot have more than 10 keywords");
@@ -82,13 +82,9 @@ export const AddNewWord = (props: any) => {
8282

8383
const addSource = (event: SelectChangeEvent) => {
8484
let cpy = {...props.newEvent};
85-
86-
if (props.newEvent.sources.indexOf(event.target.value as string) !== -1) {
87-
alert("This source already exists!");
88-
} else {
89-
cpy.sources.push(event.target.value as string);
90-
setsources(cpy);
91-
}
85+
86+
cpy.source = props.sources.find((elem: any) => elem.name === event.target.value)
87+
props.setnewEvent(cpy);
9288
};
9389

9490
const deleteKeyWord = (i: number) => {
@@ -98,16 +94,7 @@ export const AddNewWord = (props: any) => {
9894
cpy.keywords.splice(i, 1);
9995
}
10096
props.setnewEvent(cpy);
101-
};
102-
103-
const deleteSource = (i: number) => {
104-
let cpy = {...props.newEvent};
105-
106-
if (i > -1) {
107-
cpy.sources.splice(i, 1);
108-
}
109-
props.setnewEvent(cpy);
110-
};
97+
}
11198

11299
return (
113100
<>
@@ -127,7 +114,6 @@ export const AddNewWord = (props: any) => {
127114
handleChange={handleChange}
128115
addSource={addSource}
129116
deleteKeyWord={deleteKeyWord}
130-
deleteSource={deleteSource}
131117

132118
sources={props.sources}
133119
newEvent={props.newEvent}

src/Components/App/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
Link
99
} from "react-router-dom";
1010
import { Home } from '../Home/Home'
11-
import { Product } from '../Product/Product'
11+
import { Subtitles } from '../Subtitles/Subtitles'
1212
import { Report } from '../Report/Report'
1313
import { MicsLevel } from '../MicsLevel/MicsLevel';
1414
import { WordDetection } from '../WordDetection/WordDetection';
15-
import { GeneralEvent } from '../Events/GeneralEvent';
15+
import { GeneralActions } from '../Actions/GeneralActions';
1616
import { AllMics, resultFormat } from '../../Socket/interfaces';
1717
import { Scenes } from '../Scenes/Scenes';
1818
const ipcRenderer = window.require('electron').ipcRenderer
@@ -70,11 +70,11 @@ export default function App() {
7070
<Routes>
7171
<Route path='/' element={<Home/>}/>
7272
<Route path='/reports' element={<Report/>} />
73-
<Route path='/products' element={<Product/>} />
7473
<Route path='/audio/mics-level' element={<MicsLevel/>} />
7574
<Route path='/audio/word-detection' element={<WordDetection/>} />
76-
<Route path='/events/general' element={<GeneralEvent/>} />
77-
<Route path='/audio/Scenes' element={<Scenes/>} />
75+
<Route path='/video/scenes' element={<Scenes/>} />
76+
<Route path='/video/subtitles' element={<Subtitles/>} />
77+
<Route path='/action/general' element={<GeneralActions/>} />
7878
</Routes>
7979
</div>
8080
</Router>

0 commit comments

Comments
 (0)