From 69f23c9e48ed6ffdb97cba805805d8f7c97b8903 Mon Sep 17 00:00:00 2001 From: muerwre Date: Tue, 18 Dec 2018 12:19:02 +0700 Subject: [PATCH] save: public switch --- src/components/Switch.jsx | 15 ++++++++++++ src/components/dialogs/SaveDialog.jsx | 27 +++++++++++++++++----- src/styles/main.less | 1 + src/styles/save.less | 13 +++++++++-- src/styles/switch.less | 33 +++++++++++++++++++++++++++ src/utils/history.js | 4 ++-- 6 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 src/components/Switch.jsx create mode 100644 src/styles/switch.less diff --git a/src/components/Switch.jsx b/src/components/Switch.jsx new file mode 100644 index 0000000..022487b --- /dev/null +++ b/src/components/Switch.jsx @@ -0,0 +1,15 @@ +// @flow +import React from 'react'; +import classnames from 'classnames'; + +type Props = { + active: Boolean, + + onPress: Function, +} +export const Switch = ({ active, onPress = () => {} }: Props) => ( +
+); diff --git a/src/components/dialogs/SaveDialog.jsx b/src/components/dialogs/SaveDialog.jsx index 2711347..1fc6c10 100644 --- a/src/components/dialogs/SaveDialog.jsx +++ b/src/components/dialogs/SaveDialog.jsx @@ -4,6 +4,9 @@ import { toTranslit } from '$utils/format'; import { TIPS } from '$constants/tips'; import { MODES } from '$constants/modes'; import { Icon } from '$components/panels/Icon'; +import { Switch } from '$components/Switch'; + +import classnames from 'classnames'; type Props = { address: String, // initial? @@ -22,6 +25,7 @@ type Props = { type State = { address: String, title: String, + public: Boolean, }; export class SaveDialog extends React.Component { @@ -31,6 +35,7 @@ export class SaveDialog extends React.Component { this.state = { address: props.address || '', title: props.title || '', + is_public: props.public || false, }; } @@ -61,15 +66,18 @@ export class SaveDialog extends React.Component { onCopy = e => { e.preventDefault(); + const { host, protocol } = getUrlData(); + copyToClipboard(`${protocol}//${host}/${this.getAddress()}`); + }; - const { host } = getUrlData(); - copyToClipboard(`http://${host}/${this.getAddress()}`); + togglePublic = () => { + this.setState({ is_public: !this.state.is_public }); }; render() { - const { title } = this.state; + const { title, is_public } = this.state; const { save_error, save_finished, save_overwriting, width } = this.props; - const { host } = getUrlData(); + const { host, protocol } = getUrlData(); return (
@@ -83,7 +91,7 @@ export class SaveDialog extends React.Component {
- + {
-
+
+ + { + is_public + ? ' В каталоге карт' + : ' Только по ссылке' + } +
{ !save_finished &&
Отмена
diff --git a/src/styles/main.less b/src/styles/main.less index c516993..eb8364a 100644 --- a/src/styles/main.less +++ b/src/styles/main.less @@ -12,6 +12,7 @@ @import 'dialogs.less'; @import 'progress.less'; @import 'slider.less'; +@import 'switch.less'; body { font-family: 'Rubik', sans-serif; diff --git a/src/styles/save.less b/src/styles/save.less index 0d45875..77e01e8 100644 --- a/src/styles/save.less +++ b/src/styles/save.less @@ -14,7 +14,7 @@ } .save-description { - padding: 10px; + padding: 5px 10px; } .save-title-input { @@ -47,7 +47,7 @@ background: rgba(0, 0, 0, 0.2); border-radius: 2px; display: flex; - + margin-bottom: 5px; input { padding: 5px 5px 5px 2px; background: transparent; @@ -91,6 +91,7 @@ display: flex; padding: 0px; margin-top: 20px; + margin-bottom: 5px; .button { margin-left: 10px; @@ -99,6 +100,9 @@ .save-buttons-text { flex: 1; + padding: 0 10px 2px 10px; + align-items: center; + display: flex; } .save-description { @@ -114,3 +118,8 @@ padding: 0.25em; } } + +.save-controls { + padding: 5px 10px; + user-select: none; +} diff --git a/src/styles/switch.less b/src/styles/switch.less new file mode 100644 index 0000000..dc1bd01 --- /dev/null +++ b/src/styles/switch.less @@ -0,0 +1,33 @@ +.switch { + height: 1em; + width: 2em; + border-radius: 0.5em; + box-shadow: inset white 0 0 0 0.1em; + display: inline-flex; + vertical-align: text-top; + position: relative; + top: 0.05em; + margin-right: 0.5em; + transition: all 500ms; + + &::after { + content: ' '; + position: absolute; + left: 0.2em; + top: 0.2em; + width: 0.6em; + height: 0.6em; + border-radius: 0.3em; + background: white; + transition: all 500ms; + } + + &.active { + background: white; + + &::after { + left: 1.2em; + background: #333333; + } + } +} diff --git a/src/utils/history.js b/src/utils/history.js index e86932b..f3cf0ce 100644 --- a/src/utils/history.js +++ b/src/utils/history.js @@ -6,10 +6,10 @@ export const replacePath = url => history.replace(url); export const getUrlData = (url = getPath()) => { const [, path, mode] = url.split('/'); - const { host, hash } = window.location; + const { host, hash, protocol } = window.location; return { - path, mode, host, hash + path, mode, host, hash, protocol, }; };