Skip to content

Commit fa16121

Browse files
committed
save show tags to local storage, hotkey help texts
1 parent 3c25c47 commit fa16121

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

Diff for: src/Annotator/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import historyHandler from "./reducers/history-handler.js"
2121

2222
import useEventCallback from "use-event-callback"
2323
import makeImmutable, { without } from "seamless-immutable"
24+
import getFromLocalStorage from "../utils/get-from-local-storage"
2425

2526
type Props = {
2627
taskDescription?: string,
@@ -55,7 +56,7 @@ export const Annotator = ({
5556
selectedImage = images && images.length > 0 ? 0 : undefined,
5657
showPointDistances,
5758
pointDistancePrecision,
58-
showTags = true,
59+
showTags = getFromLocalStorage("showTags", true),
5960
enabledTools = [
6061
"select",
6162
"create-point",

Diff for: src/Annotator/reducers/general-reducer.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import fixTwisted from "./fix-twisted"
1111
import convertExpandingLineToPolygon from "./convert-expanding-line-to-polygon"
1212
import clamp from "clamp"
1313
import getLandmarksWithTransform from "../../utils/get-landmarks-with-transform"
14+
import setInLocalStorage from "../../utils/set-in-local-storage"
1415

1516
const getRandomId = () => Math.random().toString().split(".")[1]
1617

@@ -809,6 +810,7 @@ export default (state: MainLayoutState, action: Action) => {
809810
}
810811
case "SELECT_TOOL": {
811812
if (action.selectedTool === "show-tags") {
813+
setInLocalStorage("showTags", !state.showTags)
812814
return setIn(state, ["showTags"], !state.showTags)
813815
} else if (action.selectedTool === "show-mask") {
814816
return setIn(state, ["showMask"], !state.showMask)

Diff for: src/MainLayout/index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import RegionSelector from "../RegionSelectorSidebarBox"
2727
import ImageSelector from "../ImageSelectorSidebarBox"
2828
import HistorySidebarBox from "../HistorySidebarBox"
2929
import useEventCallback from "use-event-callback"
30+
import getHotkeyHelpText from "../utils/get-hotkey-help-text"
3031

3132
const emptyArr = []
3233
const useStyles = makeStyles(styles)
@@ -260,17 +261,20 @@ export const MainLayout = ({
260261
iconSidebarItems={[
261262
{
262263
name: "select",
263-
helperText: "Select",
264+
helperText: "Select" + getHotkeyHelpText("select_tool"),
264265
alwaysShowing: true,
265266
},
266267
{
267268
name: "pan",
268-
helperText: "Drag/Pan",
269+
helperText:
270+
"Drag/Pan (right or middle click)" +
271+
getHotkeyHelpText("pan_tool"),
269272
alwaysShowing: true,
270273
},
271274
{
272275
name: "zoom",
273-
helperText: "Zoom In/Out",
276+
helperText:
277+
"Zoom In/Out (scroll)" + getHotkeyHelpText("zoom_tool"),
274278
alwaysShowing: true,
275279
},
276280
{
@@ -280,15 +284,16 @@ export const MainLayout = ({
280284
},
281285
{
282286
name: "create-point",
283-
helperText: "Add Point",
287+
helperText: "Add Point" + getHotkeyHelpText("create_point"),
284288
},
285289
{
286290
name: "create-box",
287-
helperText: "Add Bounding Box",
291+
helperText:
292+
"Add Bounding Box" + getHotkeyHelpText("create_bounding_box"),
288293
},
289294
{
290295
name: "create-polygon",
291-
helperText: "Add Polygon",
296+
helperText: "Add Polygon" + getHotkeyHelpText("create_polygon"),
292297
},
293298
{
294299
name: "create-expanding-line",

Diff for: src/utils/get-from-local-storage.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default (key, defaultValue) => {
2+
try {
3+
return JSON.parse(window.localStorage[`__REACT_IMAGE_ANNOTATE_${key}`])
4+
} catch (e) {
5+
return defaultValue
6+
}
7+
}

Diff for: src/utils/get-hotkey-help-text.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getApplicationKeyMap } from "react-hotkeys"
2+
3+
export const getHotkeyHelpText = (commandName) => {
4+
const firstSequence = getApplicationKeyMap()[commandName]?.sequences?.[0]
5+
?.sequence
6+
7+
if (!firstSequence) return ""
8+
return ` (${firstSequence})`
9+
}
10+
11+
export default getHotkeyHelpText

Diff for: src/utils/set-in-local-storage.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default (key, val) => {
2+
window.localStorage.setItem(
3+
`__REACT_IMAGE_ANNOTATE_${key}`,
4+
JSON.stringify(val)
5+
)
6+
}

0 commit comments

Comments
 (0)