From 71b561d471637d015690a1a710be3cf400aa400b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 15 Dec 2021 16:27:02 +0000 Subject: [PATCH] Make compact layout only apply to Modern layout (#7382) --- src/components/structures/LoggedInView.tsx | 7 +++++-- src/components/views/elements/Field.tsx | 4 ++-- .../views/settings/tabs/user/AppearanceUserSettingsTab.tsx | 7 +------ src/settings/Settings.tsx | 1 + src/settings/controllers/IncompatibleController.ts | 5 ++++- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index 70c0346c49..e7fa353e51 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -147,6 +147,7 @@ class LoggedInView extends React.Component { protected readonly _roomView: React.RefObject; protected readonly _resizeContainer: React.RefObject; protected readonly resizeHandler: React.RefObject; + protected layoutWatcherRef: string; protected compactLayoutWatcherRef: string; protected backgroundImageWatcherRef: string; protected resizer: Resizer; @@ -190,6 +191,7 @@ class LoggedInView extends React.Component { ); this._matrixClient.on("RoomState.events", this.onRoomStateEvents); + this.layoutWatcherRef = SettingsStore.watchSetting("layout", null, this.onCompactLayoutChanged); this.compactLayoutWatcherRef = SettingsStore.watchSetting( "useCompactLayout", null, this.onCompactLayoutChanged, ); @@ -212,6 +214,7 @@ class LoggedInView extends React.Component { this._matrixClient.removeListener("sync", this.onSync); this._matrixClient.removeListener("RoomState.events", this.onRoomStateEvents); OwnProfileStore.instance.off(UPDATE_EVENT, this.refreshBackgroundImage); + SettingsStore.unwatchSetting(this.layoutWatcherRef); SettingsStore.unwatchSetting(this.compactLayoutWatcherRef); SettingsStore.unwatchSetting(this.backgroundImageWatcherRef); this.resizer.detach(); @@ -295,9 +298,9 @@ class LoggedInView extends React.Component { } }; - onCompactLayoutChanged = (setting, roomId, level, valueAtLevel, newValue) => { + private onCompactLayoutChanged = () => { this.setState({ - useCompactLayout: valueAtLevel, + useCompactLayout: SettingsStore.getValue("useCompactLayout"), }); }; diff --git a/src/components/views/elements/Field.tsx b/src/components/views/elements/Field.tsx index 85f397834f..1dedf77a8b 100644 --- a/src/components/views/elements/Field.tsx +++ b/src/components/views/elements/Field.tsx @@ -230,7 +230,7 @@ export default class Field extends React.PureComponent { /* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */ const { element, prefixComponent, postfixComponent, className, onValidate, children, tooltipContent, forceValidity, tooltipClassName, list, validateOnBlur, validateOnChange, validateOnFocus, - usePlaceholderAsHint, + usePlaceholderAsHint, forceTooltipVisible, ...inputProps } = this.props; // Set some defaults for the element @@ -276,7 +276,7 @@ export default class Field extends React.PureComponent { if (tooltipContent || this.state.feedback) { fieldTooltip = ; diff --git a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx index 8249f2f615..aba8ef0340 100644 --- a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx @@ -118,12 +118,7 @@ export default class AppearanceUserSettingsTab extends React.Component - + { !SettingsStore.getValue("feature_new_layout_switcher") ? v !== Layout.Group), }, "showRedactions": { supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM, diff --git a/src/settings/controllers/IncompatibleController.ts b/src/settings/controllers/IncompatibleController.ts index aa064219f9..3621a736a4 100644 --- a/src/settings/controllers/IncompatibleController.ts +++ b/src/settings/controllers/IncompatibleController.ts @@ -27,7 +27,7 @@ export default class IncompatibleController extends SettingController { public constructor( private settingName: string, private forcedValue: any = false, - private incompatibleValue: any = true, + private incompatibleValue: any | ((v: any) => boolean) = true, ) { super(); } @@ -49,6 +49,9 @@ export default class IncompatibleController extends SettingController { } public get incompatibleSetting(): boolean { + if (typeof this.incompatibleValue === "function") { + return this.incompatibleValue(SettingsStore.getValue(this.settingName)); + } return SettingsStore.getValue(this.settingName) === this.incompatibleValue; } }