Skip to content
Prev Previous commit
Next Next commit
Now we use 'HEADER_BUTTON_CLICKED' instead of creating new types and …
…reducers for next image and previous image and they added a and d
  • Loading branch information
puskuruk committed Mar 24, 2020
commit 3085fb9677ec7bd65a239fb8b7c486e5ad4dfffd
10 changes: 0 additions & 10 deletions src/Annotator/reducers/image-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ export default (state: MainLayoutImageAnnotationState, action: Action) => {
h: action.image.height
})
}
case "GO_TO_NEXT_IMAGE": {
return setIn(
state,
["selectedImage"],
(currentImageIndex + 1) % state.images.length
)
}
case "GO_TO_PREVIOUS_IMAGE": {
return (state.images.findIndex(img => img.src === state.selectedImage) - 1 + state.images.length) % state.images.length
}
}
return state
}
16 changes: 9 additions & 7 deletions src/Shortcuts/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useReducer, useEffect, useCallback } from "react"
import React, { useState, useEffect } from "react"
import SidebarBoxContainer from "../SidebarBoxContainer"
import { setIn } from "seamless-immutable"
import ShortcutField from "./ShortcutField"
Expand Down Expand Up @@ -51,17 +51,19 @@ const defaultShortcuts = {
},
"prev-image": {
action: {
type: "GO_TO_PREV_IMAGE"
type: "HEADER_BUTTON_CLICKED",
buttonName: "Prev"
},
name: "Previous Image",
key: "ArrowLeft"
key: "a"
},
"next-image": {
action: {
type: "GO_TO_NEXT_IMAGE"
type: "HEADER_BUTTON_CLICKED",
buttonName: "Next"
},
name: "Next Image",
key: "ArrowRight"
key: "d"//"ArrowRight"
}
}

Expand All @@ -85,14 +87,13 @@ export default ({ onShortcutActionDispatched }) => {
useEffect(() => {
const handleKeyPress = e => {
for (const actionId in shortcuts) {
console.log(e)
const shortcut = shortcuts[actionId]
if (!shortcut || !shortcut.key) {
continue
}
if (e.key === shortcut.key) {
onShortcutActionDispatched({
type: shortcut.action.type,
...shortcut.action,
selectedTool: actionId
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to...

onShortcutActionDispatched(shortcut.action)
}
Expand All @@ -103,6 +104,7 @@ export default ({ onShortcutActionDispatched }) => {

return () => {
window.removeEventListener("keypress", handleKeyPress)
document.activeElement.blur()
}
}, [shortcuts])

Expand Down