Interactive interface for browsing global, full-resolution satellite imagery
add copy to clipboard coords
Ed Platod7542bc0f885
diff --git a/web/css/tooltip.css b/web/css/tooltip.cssindex 0291a7707..f19f45e8e 100644--- a/web/css/tooltip.css+++ b/web/css/tooltip.css@@ -122,6 +122,11 @@}&.tooltip-coordinates-container {max-width: 420px;+ & svg.svg-inline--fa.fa-copy {+ position: absolute;+ right: 6px;+ bottom: 6px;+ }}.tooltip-coordinates-title {white-space: pre-wrap;@@ -135,6 +140,7 @@margin-top: 6px;& div:nth-child(2) {padding-left: 15px;+ padding-right: 26px;}}.close-tooltip {diff --git a/web/js/components/geosearch/coordinates-dialog.js b/web/js/components/geosearch/coordinates-dialog.jsindex 24f9b18d7..875c3af84 100644--- a/web/js/components/geosearch/coordinates-dialog.js+++ b/web/js/components/geosearch/coordinates-dialog.js@@ -1,17 +1,36 @@/* eslint-disable no-restricted-syntax */-import React, { PureComponent } from 'react';+import React, { Component } from 'react';import PropTypes from 'prop-types';+import { CopyToClipboard } from 'react-copy-to-clipboard';import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';-import { faTimes } from '@fortawesome/free-solid-svg-icons';+import { faTimes, faCopy } from '@fortawesome/free-solid-svg-icons';+import CopyClipboardTooltip from './copy-tooltip';++class CoordinatesDialog extends Component {+ constructor(props) {+ super(props);+ this.state = {+ tooltipToggleTime: 0,+ };+ }++ // set copy tooltip time+ onCopyToClipboard = () => {+ this.setState({+ tooltipToggleTime: Date.now(),+ });+ }-class CoordinatesDialog extends PureComponent {render() {const {toggleWithClose, coordinatesMetadata,} = this.props;+ const {+ tooltipToggleTime,+ } = this.state;const {- features, // { latitude, longitude }+ features, // parsed { latitude, longitude }title, // "Wairau Valley"} = coordinatesMetadata;@@ -19,6 +38,9 @@ class CoordinatesDialog extends PureComponent {const longitudeText = `Longitude: ${features.longitude} °`;return (<div className="tooltip-custom-black tooltip-static tooltip-coordinates-container">+ <CopyClipboardTooltip+ tooltipToggleTime={tooltipToggleTime}+ /><div className="tooltip-coordinates-title">{title}</div><div className="tooltip-coordinates-group"><div>@@ -31,11 +53,19 @@ class CoordinatesDialog extends PureComponent {<span className="close-tooltip close-coordinates-tooltip" onClick={toggleWithClose}><FontAwesomeIcon icon={faTimes} fixedWidth /></span>+ <CopyToClipboard+ options={window.clipboardData ? {} : { format: 'text/plain' }}+ text={`${features.latitude}, ${features.longitude}`}+ onCopy={this.onCopyToClipboard}+ >+ <FontAwesomeIcon id="copy-coordinates-to-clipboard-button" icon={faCopy} fixedWidth />+ </CopyToClipboard></div>);}}+export default CoordinatesDialog;CoordinatesDialog.propTypes = {toggleWithClose: PropTypes.func,diff --git a/web/js/components/geosearch/copy-tooltip.js b/web/js/components/geosearch/copy-tooltip.jsnew file mode 100644index 000000000..dca137b95--- /dev/null+++ b/web/js/components/geosearch/copy-tooltip.js@@ -0,0 +1,66 @@+/* eslint-disable react/destructuring-assignment */+import React, { PureComponent } from 'react';+import PropTypes from 'prop-types';+import {+ Tooltip,+} from 'reactstrap';++/*+ * @class CopyClipboardTooltip+ * @extends React.PureComponent+ */+class CopyClipboardTooltip extends PureComponent {+ constructor(props) {+ super(props);+ this.state = {+ showCopiedToolTip: false,+ };+ }++ componentDidUpdate(prevProps) {+ const { tooltipToggleTime } = this.props;+ const toolTipChange = tooltipToggleTime !== prevProps.tooltipToggleTime;+ if (toolTipChange) {+ this.updateToolTipState(toolTipChange);+ }+ }++ componentWillUnmount() {+ // clear pending timeouts+ clearTimeout(this.showCopiedToolTipTimeout);+ }++ updateToolTipState = (toolTipChange) => {+ this.setState({+ showCopiedToolTip: toolTipChange,+ });+ }++ render() {+ const { showCopiedToolTip } = this.state;+ if (showCopiedToolTip) {+ clearTimeout(this.showCopiedToolTipTimeout);+ this.showCopiedToolTipTimeout = setTimeout(() => {+ this.setState({ showCopiedToolTip: false });+ }, 2000);+ }+ return (+ <>+ <Tooltip+ placement="bottom"+ isOpen={showCopiedToolTip}+ hideArrow+ target="copy-coordinates-to-clipboard-button"+ >+ Copied to clipboard!+ </Tooltip>+ </>+ );+ }+}++CopyClipboardTooltip.propTypes = {+ tooltipToggleTime: PropTypes.number,+};++export default CopyClipboardTooltip;