summaryrefslogtreecommitdiffhomepage
path: root/app/components/Switch.js
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-02-17 17:06:21 +0000
committerAndrej Mihajlov <and@codeispoetry.ru>2017-02-17 17:06:21 +0000
commit8d35d8c06e3de2b3cd4be7bdfc28084f176b2bce (patch)
tree8925b9c3c7b285a07e14c01ff72d070f1a7088a8 /app/components/Switch.js
parent00b82cb3aa904b34d7000854bcecd3b72e012c8e (diff)
downloadmullvadvpn-8d35d8c06e3de2b3cd4be7bdfc28084f176b2bce.tar.xz
mullvadvpn-8d35d8c06e3de2b3cd4be7bdfc28084f176b2bce.zip
- Format account in settings page
- Add links to configuration - Make links work on Settings page
Diffstat (limited to 'app/components/Switch.js')
-rw-r--r--app/components/Switch.js29
1 files changed, 12 insertions, 17 deletions
diff --git a/app/components/Switch.js b/app/components/Switch.js
index 16b64b2211..e2a4b7389d 100644
--- a/app/components/Switch.js
+++ b/app/components/Switch.js
@@ -1,5 +1,8 @@
import React, { Component, PropTypes } from 'react';
+const CLICK_TIMEOUT = 1000;
+const MOVE_THRESHOLD = 10;
+
export default class Switch extends Component {
static propTypes = {
@@ -28,27 +31,21 @@ export default class Switch extends Component {
}
handleMouseMove(e) {
- if(!this.state.isTracking) {
- return;
- }
+ if(!this.state.isTracking) { return; }
- const thresholdX = 10, thresholdY = 50;
- const { x: x0, y: y0 } = this.state.initialPos;
+ const { x: startX } = this.state.initialPos;
const { pageX: x, pageY: y } = e;
- const dx = Math.abs(x0 - x);
- const dy = Math.abs(y0 - y);
+ const dx = Math.abs(startX - x);
- if(dx < thresholdX || dy > thresholdY) {
- return;
- }
+ if(dx < MOVE_THRESHOLD) { return; }
const isOn = !!this.props.isOn;
let nextOn = isOn;
- if(x < x0 && isOn) {
+ if(x < startX && isOn) {
nextOn = false;
- } else if(x > x0 && !isOn) {
+ } else if(x > startX && !isOn) {
nextOn = true;
}
@@ -68,14 +65,12 @@ export default class Switch extends Component {
}
handleChange(e) {
- console.log('ONCHANGE ' + e.target.checked);
- const delta = e.timeStamp - this.state.startTime;
- const threshold = 1000;
+ const dt = e.timeStamp - this.state.startTime;
if(this.state.ignoreChange) {
e.preventDefault();
this.setState({ ignoreChange: false });
- } else if(delta > threshold) {
+ } else if(dt > CLICK_TIMEOUT) {
e.preventDefault();
} else {
this.notify(e.target.checked);
@@ -104,4 +99,4 @@ export default class Switch extends Component {
onMouseDown={ ::this.handleMouseDown } onChange={ ::this.handleChange } />
);
}
-} \ No newline at end of file
+}