Skip to content

Commit 741081f

Browse files
updated code to use-event-callback and moved function to genereal reducers
1 parent fc13e2c commit 741081f

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

src/Annotator/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ export const Annotator = ({
121121
dispatchToReducer(action)
122122
})
123123

124-
const onRegionLabelAdded = (cls) => {
124+
const onRegionClassAdded = useEventCallback((cls) => {
125125
dispatchToReducer({
126126
type: "ON_CLS_ADDED",
127127
cls: cls,
128128
})
129-
}
129+
})
130130

131131
useEffect(() => {
132132
if (!selectedImage) return
@@ -144,7 +144,7 @@ export const Annotator = ({
144144
alwaysShowPrevButton={Boolean(onPrevImage)}
145145
state={state}
146146
dispatch={dispatch}
147-
onRegionLabelAdded={onRegionLabelAdded}
147+
onRegionClassAdded={onRegionClassAdded}
148148
/>
149149
</SettingsProvider>
150150
)

src/Annotator/reducers/general-reducer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ const getRandomColor = () => {
2222
}
2323

2424
export default (state: MainLayoutState, action: Action) => {
25+
if (action.type === "ON_CLS_ADDED" && action.cls && action.cls !== "") {
26+
const oldRegionClsList = state.regionClsList
27+
const newState = {
28+
...state,
29+
regionClsList: oldRegionClsList.concat(action.cls),
30+
}
31+
return newState
32+
}
33+
2534
// Throttle certain actions
2635
if (action.type === "MOUSE_MOVE") {
2736
if (Date.now() - ((state: any).lastMouseMoveCall || 0) < 16) return state

src/Annotator/reducers/history-handler.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ export default (reducer) => {
2626
const prevState = state
2727
const nextState = reducer(state, action)
2828

29-
if (action.type === "ON_CLS_ADDED" && action.cls && action.cls !== "") {
30-
const oldRegionClsList = state.regionClsList
31-
const newState = {
32-
...state,
33-
regionClsList: oldRegionClsList.concat(action.cls),
34-
}
35-
return newState
36-
}
37-
3829
if (action.type === "RESTORE_HISTORY") {
3930
if (state.history.length > 0) {
4031
return setIn(

src/ImageCanvas/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type Props = {
7979
duration?: number,
8080
}) => any,
8181
onChangeVideoTime: (number) => any,
82-
onRegionLabelAdded: () => {},
82+
onRegionClassAdded: () => {},
8383
}
8484

8585
const getDefaultMat = () => Matrix.from(1, 0, 0, 1, -10, -10)
@@ -119,7 +119,7 @@ export default ({
119119
onDeleteRegion,
120120
onChangeVideoTime,
121121
onChangeVideoPlaying,
122-
onRegionLabelAdded,
122+
onRegionClassAdded,
123123
}: Props) => {
124124
const classes = useStyles()
125125

@@ -443,7 +443,7 @@ export default ({
443443
layoutParams={layoutParams}
444444
imageSrc={imageSrc}
445445
RegionEditLabel={RegionEditLabel}
446-
onRegionLabelAdded={onRegionLabelAdded}
446+
onRegionClassAdded={onRegionClassAdded}
447447
/>
448448
</PreventScrollToParents>
449449
)}

src/MainLayout/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Props = {
3434
dispatch: (Action) => any,
3535
alwaysShowNextButton?: boolean,
3636
alwaysShowPrevButton?: boolean,
37-
onRegionLabelAdded: () => {},
37+
onRegionClassAdded: () => {},
3838
}
3939

4040
export default ({
@@ -43,7 +43,7 @@ export default ({
4343
alwaysShowNextButton = false,
4444
alwaysShowPrevButton = false,
4545
RegionEditLabel,
46-
onRegionLabelAdded,
46+
onRegionClassAdded,
4747
}: Props) => {
4848
const classes = useStyles()
4949
const settings = useSettings()
@@ -222,7 +222,7 @@ export default ({
222222
"CHANGE_VIDEO_PLAYING",
223223
"isPlaying"
224224
)}
225-
onRegionLabelAdded={onRegionLabelAdded}
225+
onRegionClassAdded={onRegionClassAdded}
226226
/>
227227
</div>
228228
)}

src/RegionLabel/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Props = {
2929
onChange: (Region) => null,
3030
onClose: (Region) => null,
3131
onOpen: (Region) => null,
32-
onRegionLabelAdded: () => {},
32+
onRegionClassAdded: () => {},
3333
}
3434

3535
export const RegionLabel = ({
@@ -41,7 +41,7 @@ export const RegionLabel = ({
4141
onChange,
4242
onClose,
4343
onOpen,
44-
onRegionLabelAdded,
44+
onRegionClassAdded,
4545
}: Props) => {
4646
const classes = useStyles()
4747

@@ -108,7 +108,7 @@ export const RegionLabel = ({
108108
placeholder="Classification"
109109
onChange={(o, actionMeta) => {
110110
if (actionMeta.action == "create-option") {
111-
onRegionLabelAdded(o.value)
111+
onRegionClassAdded(o.value)
112112
}
113113
return onChange({
114114
...(region: any),

src/RegionTags/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const RegionTags = ({
2626
layoutParams,
2727
imageSrc,
2828
RegionEditLabel,
29-
onRegionLabelAdded,
29+
onRegionClassAdded,
3030
}) => {
3131
const RegionLabel =
3232
RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel
@@ -116,7 +116,7 @@ export const RegionTags = ({
116116
region={region}
117117
regions={regions}
118118
imageSrc={imageSrc}
119-
onRegionLabelAdded={onRegionLabelAdded}
119+
onRegionClassAdded={onRegionClassAdded}
120120
/>
121121
</div>
122122
</div>

0 commit comments

Comments
 (0)