From 992d8309f87d2621083ea2213feb05bf3a206482 Mon Sep 17 00:00:00 2001 From: Tony Atkins Date: Tue, 10 Nov 2020 13:56:05 +0100 Subject: [PATCH 01/11] C2LC-248: Initial Implementation of share button. --- src/App.js | 3 ++ src/ProgramBlockEditor.js | 3 ++ src/ShareButton.js | 69 ++++++++++++++++++++++++++++++++++++++ src/ShareCompleteModal.css | 8 +++++ src/ShareCompleteModal.js | 34 +++++++++++++++++++ src/messages.json | 2 ++ 6 files changed, 119 insertions(+) create mode 100644 src/ShareButton.js create mode 100644 src/ShareCompleteModal.css create mode 100644 src/ShareCompleteModal.js diff --git a/src/App.js b/src/App.js index edef982d..e1d06256 100644 --- a/src/App.js +++ b/src/App.js @@ -21,6 +21,7 @@ import AudioFeedbackToggleSwitch from './AudioFeedbackToggleSwitch'; import PenDownToggleSwitch from './PenDownToggleSwitch'; import { programIsEmpty } from './ProgramUtils'; import ProgramSerializer from './ProgramSerializer'; +import ShareButton from './ShareButton'; import type { DeviceConnectionStatus, Program, RobotDriver } from './types'; import * as Utils from './Utils'; import messages from './messages.json'; @@ -593,6 +594,8 @@ export default class App extends React.Component<{}, AppState> { + + + { + static defaultProps = { + disabled: false, + showShareComplete: false + } + + constructor (props: ShareButtonProps) { + super(props); + this.state = { + showShareComplete: false + } + } + + handleClickShareButton = () => { + // Get the current URL, which represents the current program state. + const currentUrl = document.location.href; + + // Copy the URL to the clipboard, see: + // https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText + navigator.clipboard.writeText(currentUrl).then(() => { + // TODO: Display modal. + this.setState({ showShareComplete: true}) + }); + } + + handleModalClose = () => { + this.setState({showShareComplete: false}); + } + + render() { + return ( + + + + + ); + } +} + +export default injectIntl(ShareButton); + diff --git a/src/ShareCompleteModal.css b/src/ShareCompleteModal.css new file mode 100644 index 00000000..3ebafb14 --- /dev/null +++ b/src/ShareCompleteModal.css @@ -0,0 +1,8 @@ +.ShareCompleteModal { + border-radius: 0.25rem; +} + +.ShareCompleteModal__content { + border-radius: 0.25rem; + background-color: yellow; +} \ No newline at end of file diff --git a/src/ShareCompleteModal.js b/src/ShareCompleteModal.js new file mode 100644 index 00000000..d11a1a5b --- /dev/null +++ b/src/ShareCompleteModal.js @@ -0,0 +1,34 @@ +// @flow +import React from 'react'; +import { Modal } from 'react-bootstrap'; +import { injectIntl, FormattedMessage } from 'react-intl'; +import type {IntlShape} from 'react-intl'; + +import './ShareCompleteModal.css'; + +type ShareCompleteModalProps = { + intl: IntlShape, + show: boolean, + onHide: Function +}; + +class ShareCompleteModal extends React.Component { + static defaultProps = { + show: false, + onHide: () => {} + } + + render () { + return( + + + + ); + } +} + +export default injectIntl(ShareCompleteModal); \ No newline at end of file diff --git a/src/messages.json b/src/messages.json index 6ba71c4a..8c4d150d 100644 --- a/src/messages.json +++ b/src/messages.json @@ -55,6 +55,8 @@ "ProgramTextEditor.programLabel": "Program:", "AudioFeedbackToggleSwitch.audioFeedback": "Audio feedback", "Scene": "Scene", + "ShareButton": "Share", + "ShareCompleteModal.shareComplete": "The URL for your program has been copied to the clipboard.", "RefreshButton": "Refresh" }, "fr": { From 2759efe0e0fae933fd89635d0a9cd6324e8b651f Mon Sep 17 00:00:00 2001 From: Tony Atkins Date: Tue, 10 Nov 2020 16:06:11 +0100 Subject: [PATCH 02/11] C2LC-248: Initial crude integration of share button with playback controls. --- src/App.js | 41 +++++++++++++++++++++------------ src/ProgramSpeedController.scss | 1 + src/ShareButton.css | 3 +++ src/ShareButton.js | 4 ++-- 4 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 src/ShareButton.css diff --git a/src/App.js b/src/App.js index 7774cebd..e400c6d6 100644 --- a/src/App.js +++ b/src/App.js @@ -581,24 +581,35 @@ export default class App extends React.Component<{}, AppState> { /> -
-
- + + +
+
+ +
+
+ + + + -
- -
+ + + + + + - { // Copy the URL to the clipboard, see: // https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText navigator.clipboard.writeText(currentUrl).then(() => { - // TODO: Display modal. this.setState({ showShareComplete: true}) }); } @@ -51,7 +52,6 @@ class ShareButton extends React.Component {