Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 5eff2a3

Browse files
author
Luke Barnard
committed
Merge branch 'develop' into luke/fix-user-pill-onclick
2 parents bb229d3 + ecd1735 commit 5eff2a3

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

src/UserSettingsStore.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export default {
2929
name: "-",
3030
id: 'matrix_apps',
3131
default: false,
32+
33+
// XXX: Always use default, ignore localStorage and remove from labs
34+
override: true,
3235
},
3336
],
3437

@@ -171,22 +174,36 @@ export default {
171174
localStorage.setItem('mx_local_settings', JSON.stringify(settings));
172175
},
173176

174-
isFeatureEnabled: function(feature: string): boolean {
177+
getFeatureById(feature: string) {
178+
for (let i = 0; i < this.LABS_FEATURES.length; i++) {
179+
const f = this.LABS_FEATURES[i];
180+
if (f.id === feature) {
181+
return f;
182+
}
183+
}
184+
return null;
185+
},
186+
187+
isFeatureEnabled: function(featureId: string): boolean {
175188
// Disable labs for guests.
176189
if (MatrixClientPeg.get().isGuest()) return false;
177190

178-
if (localStorage.getItem(`mx_labs_feature_${feature}`) === null) {
179-
for (let i = 0; i < this.LABS_FEATURES.length; i++) {
180-
const f = this.LABS_FEATURES[i];
181-
if (f.id === feature) {
182-
return f.default;
183-
}
184-
}
191+
const feature = this.getFeatureById(featureId);
192+
if (!feature) {
193+
console.warn(`Unknown feature "${featureId}"`);
194+
return false;
195+
}
196+
// Return the default if this feature has an override to be the default value or
197+
// if the feature has never been toggled and is therefore not in localStorage
198+
if (Object.keys(feature).includes('override') ||
199+
localStorage.getItem(`mx_labs_feature_${featureId}`) === null
200+
) {
201+
return feature.default;
185202
}
186-
return localStorage.getItem(`mx_labs_feature_${feature}`) === 'true';
203+
return localStorage.getItem(`mx_labs_feature_${featureId}`) === 'true';
187204
},
188205

189-
setFeatureEnabled: function(feature: string, enabled: boolean) {
190-
localStorage.setItem(`mx_labs_feature_${feature}`, enabled);
206+
setFeatureEnabled: function(featureId: string, enabled: boolean) {
207+
localStorage.setItem(`mx_labs_feature_${featureId}`, enabled);
191208
},
192209
};

src/components/structures/UserSettings.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,21 @@ module.exports = React.createClass({
859859
if (this.props.enableLabs === false) return null;
860860
UserSettingsStore.doTranslations();
861861

862-
const features = UserSettingsStore.LABS_FEATURES.map((feature) => {
862+
const features = [];
863+
UserSettingsStore.LABS_FEATURES.forEach((feature) => {
864+
// This feature has an override and will be set to the default, so do not
865+
// show it here.
866+
if (feature.override) {
867+
return;
868+
}
863869
// TODO: this ought to be a separate component so that we don't need
864870
// to rebind the onChange each time we render
865871
const onChange = (e) => {
866872
UserSettingsStore.setFeatureEnabled(feature.id, e.target.checked);
867873
this.forceUpdate();
868874
};
869875

870-
return (
876+
features.push(
871877
<div key={feature.id} className="mx_UserSettings_toggle">
872878
<input
873879
type="checkbox"
@@ -877,9 +883,14 @@ module.exports = React.createClass({
877883
onChange={ onChange }
878884
/>
879885
<label htmlFor={feature.id}>{feature.name}</label>
880-
</div>
881-
);
886+
</div>);
882887
});
888+
889+
// No labs section when there are no features in labs
890+
if (features.length === 0) {
891+
return null;
892+
}
893+
883894
return (
884895
<div>
885896
<h3>{ _t("Labs") }</h3>

0 commit comments

Comments
 (0)