From 8f53b499a144f82af4cd4abffb61bbe6ffe5009d Mon Sep 17 00:00:00 2001 From: David Quartey <42542676+DavidQuartz@users.noreply.github.com> Date: Fri, 5 Aug 2022 09:15:54 +0000 Subject: [PATCH] [Fixes 1122] Issues with pressing Enter in Clone dialog (#1133) (#1140) * Fixes 1122 * Added enter for new maps --- .../client/js/plugins/save/SaveModal.jsx | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/geonode_mapstore_client/client/js/plugins/save/SaveModal.jsx b/geonode_mapstore_client/client/js/plugins/save/SaveModal.jsx index 3055331066..68eadc2bf4 100644 --- a/geonode_mapstore_client/client/js/plugins/save/SaveModal.jsx +++ b/geonode_mapstore_client/client/js/plugins/save/SaveModal.jsx @@ -64,30 +64,25 @@ function SaveModal({ const isLoading = loading || saving; - - useEffect(() => { - // clone on enter key press - if (copy && currentModal?.current) { - currentModal?.current?.addEventListener('keyup', (event) => { - if (event.keyCode === 13) { - event.stopPropagation(); - onSave( - update ? contentId : undefined, - { - thumbnail, - name, - description - }, - true); - } - }); - } - return () => currentModal?.current?.removeEventListener('keyup', () => {}); - }, []); + const handleEnterPress = options => { + const {title, isUpdate, content, image, text, reload} = options; + return onSave( + isUpdate ? content : undefined, + { + thumbnail: image, + name: title, + description: text + }, + reload); + }; return ( -
+
{ + e.stopPropagation(); + return (e.keyCode === 13 || e.code === 'Enter') && (copy ? handleEnterPress({title: name, isUpdate: update, content: contentId, image: thumbnail, text: description, reload: false}) : handleEnterPress({title: name, isUpdate: update, content: contentId, image: thumbnail, text: description, reload: true})); + } + }> } show={enabled} @@ -122,7 +117,8 @@ function SaveModal({ {success &&
} -
+ {/* prevent reload on enter key press from implicit submission */} + e.preventDefault()}>