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} />