From c3a96583928305e42a5bb5f5296dde4cd1a0583d Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Mon, 13 Jun 2016 22:04:12 +0530 Subject: [PATCH 1/3] Add experimental "Labs" section to settings --- src/UserSettingsStore.js | 10 +++++++ src/components/structures/UserSettings.js | 33 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index 9bb1388e76..f9c8a3ed2d 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -112,4 +112,14 @@ module.exports = { append: true, // We always append for email pushers since we don't want to stop other accounts notifying to the same email address }); }, + + isFeatureEnabled: function(feature: string): boolean { + feature = feature.match(/\w+/g).join('_').toLowerCase(); + return localStorage.getItem(`mx_labs_feature_${feature}`) === 'true'; + }, + + setFeatureEnabled: function(feature: string, enabled: boolean) { + feature = feature.match(/\w+/g).join('_').toLowerCase(); + localStorage.setItem(`mx_labs_feature_${feature}`, enabled); + } }; diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 635f9c5413..fcb1254af0 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -26,6 +26,11 @@ var GeminiScrollbar = require('react-gemini-scrollbar'); var Email = require('../../email'); var AddThreepid = require('../../AddThreepid'); +const LABS_FEATURES = [ + 'Rich Text Editor', + 'End-to-End Encryption' +]; + module.exports = React.createClass({ displayName: 'UserSettings', @@ -357,6 +362,32 @@ module.exports = React.createClass({ ); } + this._renderLabs = function () { + let features = LABS_FEATURES.map(feature => ( +
+ UserSettingsStore.setFeatureEnabled(feature, e.target.checked)} /> + +
+ )); + return ( +
+

Labs

+ +
+

These experimental features may change, break or disappear at any time. We make absolutely no guarantees about what may happen if you turn one of these experiments on, and your client may even spontaneously combust. Jokes aside, your client may delete all your data or your security and privacy could be compromised in unexpected ways. Please proceed with caution.

+ {features} +
+
window.location.reload()}>Restart Vector
+
+
+ ) + }; + return (
@@ -411,6 +442,8 @@ module.exports = React.createClass({ {this._renderDeviceInfo()} + {this._renderLabs()} +

Advanced

From 727e6daaae62a7f80e36333e46c3ad001f10f857 Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Mon, 13 Jun 2016 22:11:21 +0530 Subject: [PATCH 2/3] Fix key attr placement in UserSettings --- src/components/structures/UserSettings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index fcb1254af0..2023082422 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -364,8 +364,8 @@ module.exports = React.createClass({ this._renderLabs = function () { let features = LABS_FEATURES.map(feature => ( -
- + Date: Mon, 13 Jun 2016 23:25:31 +0530 Subject: [PATCH 3/3] Labs improvements --- src/UserSettingsStore.js | 2 -- src/components/structures/UserSettings.js | 26 +++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index f9c8a3ed2d..305994aa0e 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -114,12 +114,10 @@ module.exports = { }, isFeatureEnabled: function(feature: string): boolean { - feature = feature.match(/\w+/g).join('_').toLowerCase(); return localStorage.getItem(`mx_labs_feature_${feature}`) === 'true'; }, setFeatureEnabled: function(feature: string, enabled: boolean) { - feature = feature.match(/\w+/g).join('_').toLowerCase(); localStorage.setItem(`mx_labs_feature_${feature}`, enabled); } }; diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 2023082422..a320a02da8 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -27,8 +27,14 @@ var Email = require('../../email'); var AddThreepid = require('../../AddThreepid'); const LABS_FEATURES = [ - 'Rich Text Editor', - 'End-to-End Encryption' + { + name: 'Rich Text Editor', + id: 'rich_text_editor' + }, + { + name: 'End-to-End Encryption', + id: 'e2e_encryption' + } ]; module.exports = React.createClass({ @@ -364,14 +370,14 @@ module.exports = React.createClass({ this._renderLabs = function () { let features = LABS_FEATURES.map(feature => ( -
+
UserSettingsStore.setFeatureEnabled(feature, e.target.checked)} /> - + id={feature.id} + name={feature.id} + defaultChecked={UserSettingsStore.isFeatureEnabled(feature.id)} + onChange={e => UserSettingsStore.setFeatureEnabled(feature.id, e.target.checked)} /> +
)); return ( @@ -379,10 +385,8 @@ module.exports = React.createClass({

Labs

-

These experimental features may change, break or disappear at any time. We make absolutely no guarantees about what may happen if you turn one of these experiments on, and your client may even spontaneously combust. Jokes aside, your client may delete all your data or your security and privacy could be compromised in unexpected ways. Please proceed with caution.

+

These are experimental features that may break in unexpected ways. Use with caution.

{features} -
-
window.location.reload()}>Restart Vector
)