From f4e2142b15719a668a86fca50a46466da0d5d434 Mon Sep 17 00:00:00 2001 From: muerwre Date: Wed, 12 Dec 2018 12:22:49 +0700 Subject: [PATCH] save: ability to copy-to-clipboard --- src/components/dialogs/SaveDialog.jsx | 26 +++++++++++++++++++++++--- src/index.js | 5 +++-- src/sprites/icon.svg | 7 ++++++- src/styles/save.less | 18 ++++++++++++++++++ src/utils/history.js | 11 +++++++++++ 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/components/dialogs/SaveDialog.jsx b/src/components/dialogs/SaveDialog.jsx index 84a35ba..2711347 100644 --- a/src/components/dialogs/SaveDialog.jsx +++ b/src/components/dialogs/SaveDialog.jsx @@ -1,8 +1,9 @@ import React from 'react'; -import { getUrlData } from '$utils/history'; +import { copyToClipboard, getUrlData } from '$utils/history'; import { toTranslit } from '$utils/format'; import { TIPS } from '$constants/tips'; import { MODES } from '$constants/modes'; +import { Icon } from '$components/panels/Icon'; type Props = { address: String, // initial? @@ -37,7 +38,7 @@ export class SaveDialog extends React.Component { const { path } = getUrlData(); const { title, address } = this.state; - return toTranslit(address.trim()) || toTranslit(title.trim().toLowerCase()) || toTranslit(path.trim()); + return toTranslit(address.trim()) || toTranslit(title.trim().toLowerCase()) || toTranslit(path.trim()).substr(0, 32); }; setTitle = ({ target: { value } }) => this.setState({ title: (value || '') }); @@ -58,6 +59,13 @@ export class SaveDialog extends React.Component { forceSaveRequest = e => this.sendSaveRequest(e, true); + onCopy = e => { + e.preventDefault(); + + const { host } = getUrlData(); + copyToClipboard(`http://${host}/${this.getAddress()}`); + }; + render() { const { title } = this.state; const { save_error, save_finished, save_overwriting, width } = this.props; @@ -76,7 +84,16 @@ export class SaveDialog extends React.Component {
- + +
+ +
@@ -97,6 +114,9 @@ export class SaveDialog extends React.Component { save_overwriting &&
Перезаписать
} + { save_finished && +
Скопировать
+ } { save_finished &&
Отлично, спасибо!
} diff --git a/src/index.js b/src/index.js index a0d7b8b..837d1be 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,10 @@ /* + todo add ability to copy-paste address after saving - todo hide sticker dialog on sticker selection - todo separate mode for stricker selection todo save progress + done hide sticker dialog on sticker selection + done separate mode for stricker selection done TEST: set initialData after saving map, clear is-modified done TEST: provider / logo triggers setChanged done shot mechanism (100%) diff --git a/src/sprites/icon.svg b/src/sprites/icon.svg index 630f9bd..1987e6d 100644 --- a/src/sprites/icon.svg +++ b/src/sprites/icon.svg @@ -343,8 +343,13 @@ + + + + + - + diff --git a/src/styles/save.less b/src/styles/save.less index 46f5b51..3b763fe 100644 --- a/src/styles/save.less +++ b/src/styles/save.less @@ -70,6 +70,24 @@ white-space: nowrap; } +.save-address-copy { + background: rgba(255, 255, 255, 0.1); + padding: 0 5px; + border-radius: 0 @panel_radius @panel_radius 0; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + transition: background-color 250ms; + + &:hover { + background: rgba(255, 255, 255, 0.2); + } + + svg { + fill: white; + } +} .save-text { padding: 10px; line-height: 1.1em; diff --git a/src/utils/history.js b/src/utils/history.js index 3585a25..e86932b 100644 --- a/src/utils/history.js +++ b/src/utils/history.js @@ -33,3 +33,14 @@ export const pushLoaderState = state => { export const pushNetworkInitError = state => { document.getElementById('loader-error').style.opacity = 1; }; + +export const copyToClipboard = str => { + const el = document.createElement('textarea'); + el.value = str; + el.setAttribute('readonly', ''); + el.style = { position: 'absolute', left: '-9999px' }; + document.body.appendChild(el); + el.select(); + document.execCommand('copy'); + document.body.removeChild(el); +}