Skip to content

Commit

Permalink
fix: Merge pull request #244 from UniversalDataTool/disable-hotkeys
Browse files Browse the repository at this point in the history
Allow disable hotkeys mode for image classification (as prop)
  • Loading branch information
seveibar authored Aug 8, 2020
2 parents 2257a60 + e00cdaf commit 60e0a57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/ImageClassification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export default ({
iface.labels = iface.availableLabels
}

const disableHotkeys = containerProps.disableHotkeys

if (!iface.labels)
throw new Error("No labels defined. Add some labels in Setup to continue.")
const [sampleIndex, changeSampleIndex] = useState(0)
Expand Down Expand Up @@ -154,6 +156,7 @@ export default ({
}, [sampleIndex, globalSampleIndex, samples])

const [hotkeyMap, labelKeyMap] = useMemo(() => {
if (disableHotkeys) return [{}, {}]
const hotkeyMap = {
" ": onNext,
backspace: onPrev,
Expand All @@ -172,9 +175,10 @@ export default ({
labelKeyMap[label.id] = nextAvailableLetter
}
return [hotkeyMap, labelKeyMap]
}, [labels, onClickLabel, onDone, onNext, onPrev])
}, [labels, onClickLabel, onDone, onNext, onPrev, disableHotkeys])

useEffect(() => {
if (disableHotkeys) return
const onKeyDown = (e) => {
const key = e.key.toLowerCase()
if (hotkeyMap[key]) {
Expand All @@ -185,7 +189,7 @@ export default ({
return () => {
window.removeEventListener("keydown", onKeyDown)
}
}, [hotkeyMap])
}, [hotkeyMap, disableHotkeys])

return (
<WorkspaceContainer
Expand Down
3 changes: 3 additions & 0 deletions src/components/UniversalDataViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const UniversalDataViewer = ({
onExit,
hideHeader,
hideDescription,
disableHotkeys = false,
datasetName,
requireCompleteToPressNext,
onSaveTaskOutputItem,
Expand All @@ -36,6 +37,7 @@ export const UniversalDataViewer = ({
requireCompleteToPressNext,
onExit,
height,
disableHotkeys,
}),
[
hideHeader,
Expand All @@ -44,6 +46,7 @@ export const UniversalDataViewer = ({
datasetName,
height,
onExit,
disableHotkeys,
]
)

Expand Down

0 comments on commit 60e0a57

Please sign in to comment.