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

Commit

Permalink
Make compact layout only apply to Modern layout (#7382)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Dec 15, 2021
1 parent d9da258 commit 71b561d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class LoggedInView extends React.Component<IProps, IState> {
protected readonly _roomView: React.RefObject<any>;
protected readonly _resizeContainer: React.RefObject<HTMLDivElement>;
protected readonly resizeHandler: React.RefObject<HTMLDivElement>;
protected layoutWatcherRef: string;
protected compactLayoutWatcherRef: string;
protected backgroundImageWatcherRef: string;
protected resizer: Resizer;
Expand Down Expand Up @@ -190,6 +191,7 @@ class LoggedInView extends React.Component<IProps, IState> {
);
this._matrixClient.on("RoomState.events", this.onRoomStateEvents);

this.layoutWatcherRef = SettingsStore.watchSetting("layout", null, this.onCompactLayoutChanged);
this.compactLayoutWatcherRef = SettingsStore.watchSetting(
"useCompactLayout", null, this.onCompactLayoutChanged,
);
Expand All @@ -212,6 +214,7 @@ class LoggedInView extends React.Component<IProps, IState> {
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();
Expand Down Expand Up @@ -295,9 +298,9 @@ class LoggedInView extends React.Component<IProps, IState> {
}
};

onCompactLayoutChanged = (setting, roomId, level, valueAtLevel, newValue) => {
private onCompactLayoutChanged = () => {
this.setState({
useCompactLayout: valueAtLevel,
useCompactLayout: SettingsStore.getValue("useCompactLayout"),
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/views/elements/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
/* 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 <input> element
Expand Down Expand Up @@ -276,7 +276,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
if (tooltipContent || this.state.feedback) {
fieldTooltip = <Tooltip
tooltipClassName={classNames("mx_Field_tooltip", tooltipClassName)}
visible={(this.state.focused && this.props.forceTooltipVisible) || this.state.feedbackVisible}
visible={(this.state.focused && forceTooltipVisible) || this.state.feedbackVisible}
label={tooltipContent || this.state.feedback}
alignment={Tooltip.Alignment.Right}
/>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ export default class AppearanceUserSettingsTab extends React.Component<IProps, I
{ brand },
);
advanced = <>
<SettingsFlag
name="useCompactLayout"
level={SettingLevel.DEVICE}
useCheckbox={true}
disabled={this.state.layout !== Layout.Group}
/>
<SettingsFlag name="useCompactLayout" level={SettingLevel.DEVICE} useCheckbox={true} />

{ !SettingsStore.getValue("feature_new_layout_switcher") ?
<StyledCheckbox
Expand Down
1 change: 1 addition & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ export const SETTINGS: {[setting: string]: ISetting} = {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
displayName: _td("Use a more compact 'Modern' layout"),
default: false,
controller: new IncompatibleController("layout", false, v => v !== Layout.Group),
},
"showRedactions": {
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
Expand Down
5 changes: 4 additions & 1 deletion src/settings/controllers/IncompatibleController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
}
}

0 comments on commit 71b561d

Please sign in to comment.