From 34a0be6d441e1e3b2c37f9af177fe57de662c4b6 Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Wed, 27 Nov 2024 01:24:45 +0100 Subject: [PATCH] Enable actions for highlights in the note editor. Fix #570 --- modules/note-editor | 2 +- src/js/common/navigation.js | 6 ++++-- src/js/component/rich-editor.jsx | 6 ++++++ src/js/reducers/current.js | 10 +++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/note-editor b/modules/note-editor index 0f15a7f7..876842ca 160000 --- a/modules/note-editor +++ b/modules/note-editor @@ -1 +1 @@ -Subproject commit 0f15a7f7ea4077f567f0cebbc847b6337b70ba3c +Subproject commit 876842ca760c26bef5cd7abb5edbc321b3a15cca diff --git a/src/js/common/navigation.js b/src/js/common/navigation.js index 929e1762..a0bd1655 100644 --- a/src/js/common/navigation.js +++ b/src/js/common/navigation.js @@ -71,8 +71,10 @@ const makePath = (config, { library = null, collection = null, } if (location && ['pageNumber', 'annotationID', 'position', 'href'].includes(Object.keys(location)[0])) { - path.push(Object.keys(location)[0]) - path.push(location[Object.keys(location)[0]]) + const locationType = Object.keys(location)[0]; + const locationValue = location[locationType]; + path.push(locationType); + path.push(locationType === 'position' ? JSON.stringify(locationValue) : locationValue); } return '/' + path.join('/'); diff --git a/src/js/component/rich-editor.jsx b/src/js/component/rich-editor.jsx index 1206272b..45b17116 100644 --- a/src/js/component/rich-editor.jsx +++ b/src/js/component/rich-editor.jsx @@ -124,6 +124,12 @@ const RichEditor = memo(forwardRef((props, ref) => { } break; } + case 'openAnnotation': { + let { attachmentURI, position } = event.data?.message ?? {}; + const { libraryKey, itemKey } = getItemFromCanonicalUrl(attachmentURI) ?? {}; + dispatch(openInReader({ items: itemKey, library: libraryKey, location: { position } })); + break; + } default: break; } diff --git a/src/js/reducers/current.js b/src/js/reducers/current.js index b25d5f99..fac1d4ef 100644 --- a/src/js/reducers/current.js +++ b/src/js/reducers/current.js @@ -61,6 +61,14 @@ const getLibraryKey = (params, config) => { return config.defaultLibraryKey; } +const tryParse = (value) => { + try { + return JSON.parse(value); + } catch(e) { + return null; + } +}; + const current = (state = stateDefault, action, { config = {}, device = {}, preferences = {} } = {}) => { switch(action.type) { @@ -91,7 +99,7 @@ const current = (state = stateDefault, action, { config = {}, device = {}, prefe var searchState = state.searchState; var itemKey = itemKeys && itemKeys.length === 1 ? itemKeys[0] : null var location = params.locationType && params.locationValue ? { - [params.locationType]: params.locationValue + [params.locationType]: params.locationType === 'position' ? tryParse(params.locationValue) : params.locationValue } : null; if(tags.length || search.length) {