Skip to content

Commit 60e0a57

Browse files
authored
fix: Merge pull request #244 from UniversalDataTool/disable-hotkeys
Allow disable hotkeys mode for image classification (as prop)
2 parents 2257a60 + e00cdaf commit 60e0a57

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/components/ImageClassification/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export default ({
8383
iface.labels = iface.availableLabels
8484
}
8585

86+
const disableHotkeys = containerProps.disableHotkeys
87+
8688
if (!iface.labels)
8789
throw new Error("No labels defined. Add some labels in Setup to continue.")
8890
const [sampleIndex, changeSampleIndex] = useState(0)
@@ -154,6 +156,7 @@ export default ({
154156
}, [sampleIndex, globalSampleIndex, samples])
155157

156158
const [hotkeyMap, labelKeyMap] = useMemo(() => {
159+
if (disableHotkeys) return [{}, {}]
157160
const hotkeyMap = {
158161
" ": onNext,
159162
backspace: onPrev,
@@ -172,9 +175,10 @@ export default ({
172175
labelKeyMap[label.id] = nextAvailableLetter
173176
}
174177
return [hotkeyMap, labelKeyMap]
175-
}, [labels, onClickLabel, onDone, onNext, onPrev])
178+
}, [labels, onClickLabel, onDone, onNext, onPrev, disableHotkeys])
176179

177180
useEffect(() => {
181+
if (disableHotkeys) return
178182
const onKeyDown = (e) => {
179183
const key = e.key.toLowerCase()
180184
if (hotkeyMap[key]) {
@@ -185,7 +189,7 @@ export default ({
185189
return () => {
186190
window.removeEventListener("keydown", onKeyDown)
187191
}
188-
}, [hotkeyMap])
192+
}, [hotkeyMap, disableHotkeys])
189193

190194
return (
191195
<WorkspaceContainer

src/components/UniversalDataViewer/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const UniversalDataViewer = ({
2020
onExit,
2121
hideHeader,
2222
hideDescription,
23+
disableHotkeys = false,
2324
datasetName,
2425
requireCompleteToPressNext,
2526
onSaveTaskOutputItem,
@@ -36,6 +37,7 @@ export const UniversalDataViewer = ({
3637
requireCompleteToPressNext,
3738
onExit,
3839
height,
40+
disableHotkeys,
3941
}),
4042
[
4143
hideHeader,
@@ -44,6 +46,7 @@ export const UniversalDataViewer = ({
4446
datasetName,
4547
height,
4648
onExit,
49+
disableHotkeys,
4750
]
4851
)
4952

0 commit comments

Comments
 (0)