From e00cdaf88e878b7f33a85270f712d7cd002dda4b Mon Sep 17 00:00:00 2001 From: seveibar Date: Fri, 7 Aug 2020 20:09:22 -0400 Subject: [PATCH] disable hotkeys mode for image classification --- src/components/ImageClassification/index.js | 8 ++++++-- src/components/UniversalDataViewer/index.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/ImageClassification/index.js b/src/components/ImageClassification/index.js index c4f36aa2..2533e35e 100644 --- a/src/components/ImageClassification/index.js +++ b/src/components/ImageClassification/index.js @@ -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) @@ -154,6 +156,7 @@ export default ({ }, [sampleIndex, globalSampleIndex, samples]) const [hotkeyMap, labelKeyMap] = useMemo(() => { + if (disableHotkeys) return [{}, {}] const hotkeyMap = { " ": onNext, backspace: onPrev, @@ -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]) { @@ -185,7 +189,7 @@ export default ({ return () => { window.removeEventListener("keydown", onKeyDown) } - }, [hotkeyMap]) + }, [hotkeyMap, disableHotkeys]) return (