diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 89acb04df..562986a26 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -9,6 +9,8 @@ ### Fixes - Makes settings scrollable on shorter smaller view ports [#1767](https://github.com/Automattic/simplenote-electron/pull/1767) +- Added indication that publish url has been copied [#1743](https://github.com/Automattic/simplenote-electron/pull/1743) + ### Other Changes - Updated dependencies [#1759](https://github.com/Automattic/simplenote-electron/pull/1759) @@ -17,7 +19,7 @@ ### Enhancements - - Added matching tags to the notes list on search [#1648](https://github.com/Automattic/simplenote-electron/pull/1648) +- Added matching tags to the notes list on search [#1648](https://github.com/Automattic/simplenote-electron/pull/1648) ### Fixes diff --git a/lib/components/clipboard-button/index.jsx b/lib/components/clipboard-button/index.jsx new file mode 100644 index 000000000..218c0f69d --- /dev/null +++ b/lib/components/clipboard-button/index.jsx @@ -0,0 +1,53 @@ +import React, { useEffect, useRef, useState } from 'react'; +import PropTypes from 'prop-types'; +import ReactDom from 'react-dom'; +import Clipboard from 'clipboard'; + +function ClipboardButton({ text }) { + const buttonRef = useRef(); + const textCallback = useRef(); + const successCallback = useRef(); + + const onCopy = () => { + setCopied(true); + }; + + const [isCopied, setCopied] = useState(false); + + // toggle the `isCopied` flag back to `false` after 4 seconds + useEffect(() => { + if (isCopied) { + const confirmationTimeout = setTimeout(() => setCopied(false), 4000); + return () => clearTimeout(confirmationTimeout); + } + }, [isCopied]); + + // update the callbacks on rerenders that change `text` or `onCopy` + useEffect(() => { + textCallback.current = () => text; + successCallback.current = onCopy; + }, [text, onCopy]); + + // create the `Clipboard` object on mount and destroy on unmount + useEffect(() => { + const clipboard = new Clipboard(buttonRef.current, { + text: () => textCallback.current(), + }); + clipboard.on('success', () => successCallback.current()); + + return () => clipboard.destroy(); + }, []); + + return ( + + ); +} + +ClipboardButton.propTypes = { + disbaled: PropTypes.bool, + text: PropTypes.string, +}; + +export default ClipboardButton; diff --git a/lib/dialogs/settings/style.scss b/lib/dialogs/settings/style.scss index 27183cf9f..1b8bfd748 100644 --- a/lib/dialogs/settings/style.scss +++ b/lib/dialogs/settings/style.scss @@ -45,10 +45,6 @@ border-bottom: none; } - .button-borderless { - padding-right: 0; - } - .settings-item-label { flex: 1 1 auto; align-items: center; diff --git a/lib/dialogs/share/index.jsx b/lib/dialogs/share/index.jsx index 7cd9c0571..7ef7743dc 100644 --- a/lib/dialogs/share/index.jsx +++ b/lib/dialogs/share/index.jsx @@ -5,6 +5,7 @@ import { includes, isEmpty } from 'lodash'; import MD5 from 'md5.js'; import analytics from '../../analytics'; +import ClipboardButton from '../../components/clipboard-button'; import isEmailTag from '../../utils/is-email-tag'; import { updateNoteTags } from '../../state/domain/notes'; import Dialog from '../../dialog'; @@ -33,18 +34,6 @@ export class ShareDialog extends Component { }); }; - copyPublishURL = () => { - this.publishUrlElement.select(); - - try { - document.execCommand('copy'); - } catch (err) { - return; - } - - this.copyUrlElement.focus(); - }; - getPublishURL = url => (isEmpty(url) ? undefined : `http://simp.ly/p/${url}`); onAddCollaborator = event => { @@ -200,15 +189,7 @@ export class ShareDialog extends Component { spellCheck={false} />
- + {publishURL && }
@@ -222,7 +203,4 @@ export class ShareDialog extends Component { } } -export default connect( - null, - { updateNoteTags } -)(ShareDialog); +export default connect(null, { updateNoteTags })(ShareDialog); diff --git a/package-lock.json b/package-lock.json index 295565c59..075ef9912 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4957,6 +4957,16 @@ "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", "dev": true }, + "clipboard": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.4.tgz", + "integrity": "sha512-Vw26VSLRpJfBofiVaFb/I8PVfdI1OxKcYShe6fm0sP/DtmiWQNCjhM/okTvdCo0G+lMMm1rMYbk4IK4x1X+kgQ==", + "requires": { + "good-listener": "^1.2.2", + "select": "^1.1.2", + "tiny-emitter": "^2.0.0" + } + }, "cliui": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", @@ -5882,6 +5892,11 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "delegate": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/delegate/-/delegate-3.2.0.tgz", + "integrity": "sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==" + }, "delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", @@ -8765,6 +8780,14 @@ } } }, + "good-listener": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz", + "integrity": "sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=", + "requires": { + "delegate": "^3.1.2" + } + }, "got": { "version": "6.7.1", "resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", @@ -14623,6 +14646,11 @@ } } }, + "select": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz", + "integrity": "sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=" + }, "select-hose": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz", @@ -16005,6 +16033,11 @@ "setimmediate": "^1.0.4" } }, + "tiny-emitter": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz", + "integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==" + }, "tiny-warning": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz", diff --git a/package.json b/package.json index c4381d4aa..942c5a3ed 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "@automattic/color-studio": "2.2.0", "@material-ui/core": "4.7.1", "bottleneck": "2.19.5", + "clipboard": "2.0.4", "cookie": "0.4.0", "core-js": "3.4.7", "date-fns": "2.8.1",