From 85f5ec3a94402a14667486518353036a2d431f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 6 Aug 2021 10:27:18 +0200 Subject: [PATCH 1/5] Move LayoutSwitcher into a separate component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../views/settings/LayoutSwitcher.tsx | 129 ++++++++++++++++++ .../tabs/user/AppearanceUserSettingsTab.tsx | 98 +++---------- 2 files changed, 145 insertions(+), 82 deletions(-) create mode 100644 src/components/views/settings/LayoutSwitcher.tsx diff --git a/src/components/views/settings/LayoutSwitcher.tsx b/src/components/views/settings/LayoutSwitcher.tsx new file mode 100644 index 0000000000..4796519ee1 --- /dev/null +++ b/src/components/views/settings/LayoutSwitcher.tsx @@ -0,0 +1,129 @@ +/* +Copyright 2021 Šimon Brandner + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import React from "react"; +import classNames from "classnames"; +import SettingsStore from "../../../settings/SettingsStore"; +import EventTilePreview from "../elements/EventTilePreview"; +import StyledRadioButton from "../elements/StyledRadioButton"; +import { _t } from "../../../languageHandler"; +import { Layout } from "../../../settings/Layout"; +import { SettingLevel } from "../../../settings/SettingLevel"; + +interface IProps { + userId: string; + displayName: string; + avatarUrl: string; + messagePreviewText: string; + onLayoutChanged?: (layout: Layout) => void; +} + +interface IState { + layout: Layout; +} + +export default class LayoutSwitcher extends React.Component { + constructor(props: IProps) { + super(props); + + this.state = { + layout: SettingsStore.getValue("layout"), + }; + } + + private onLayoutChange = (e: React.ChangeEvent): void => { + const layout = e.target.value as Layout; + + this.setState({ layout: layout }); + SettingsStore.setValue("layout", null, SettingLevel.DEVICE, layout); + this.props.onLayoutChanged(layout); + }; + + public render(): JSX.Element { + const ircClasses = classNames("mx_AppearanceUserSettingsTab_Layout_RadioButton", { + mx_AppearanceUserSettingsTab_Layout_RadioButton_selected: this.state.layout == Layout.IRC, + }); + const groupClasses = classNames("mx_AppearanceUserSettingsTab_Layout_RadioButton", { + mx_AppearanceUserSettingsTab_Layout_RadioButton_selected: this.state.layout == Layout.Group, + }); + const bubbleClasses = classNames("mx_AppearanceUserSettingsTab_Layout_RadioButton", { + mx_AppearanceUserSettingsTab_Layout_RadioButton_selected: this.state.layout === Layout.Bubble, + }); + + return
+ + { _t("Message layout") } + + +
+ + + +
+
; + } +} diff --git a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx index 44873816dc..e4cae80406 100644 --- a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx @@ -37,10 +37,9 @@ import StyledRadioGroup from "../../../elements/StyledRadioGroup"; import { SettingLevel } from "../../../../../settings/SettingLevel"; import { UIFeature } from "../../../../../settings/UIFeature"; import { Layout } from "../../../../../settings/Layout"; -import classNames from 'classnames'; -import StyledRadioButton from '../../../elements/StyledRadioButton'; import { replaceableComponent } from "../../../../../utils/replaceableComponent"; import { compare } from "../../../../../utils/strings"; +import LayoutSwitcher from "../../LayoutSwitcher"; interface IProps { } @@ -243,17 +242,8 @@ export default class AppearanceUserSettingsTab extends React.Component): void => { - let layout; - switch (e.target.value) { - case "irc": layout = Layout.IRC; break; - case "group": layout = Layout.Group; break; - case "bubble": layout = Layout.Bubble; break; - } - + private onLayoutChanged = (layout: Layout): void => { this.setState({ layout: layout }); - - SettingsStore.setValue("layout", null, SettingLevel.DEVICE, layout); }; private onIRCLayoutChange = (enabled: boolean) => { @@ -391,75 +381,6 @@ export default class AppearanceUserSettingsTab extends React.Component; } - private renderLayoutSection = () => { - return
- { _t("Message layout") } - -
- - - -
-
; - }; - private renderAdvancedSection() { if (!SettingsStore.getValue(UIFeature.AdvancedSettings)) return null; @@ -527,6 +448,19 @@ export default class AppearanceUserSettingsTab extends React.Component + ); + } + return (
{ _t("Customise your appearance") }
@@ -534,7 +468,7 @@ export default class AppearanceUserSettingsTab extends React.Component { this.renderThemeSection() } - { SettingsStore.getValue("feature_new_layout_switcher") ? this.renderLayoutSection() : null } + { layoutSection } { this.renderFontSection() } { this.renderAdvancedSection() }
From 186acf92a988e7f1b338b59aa8739655e65dde76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 6 Aug 2021 10:30:38 +0200 Subject: [PATCH 2/5] Wrap in () MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../views/settings/LayoutSwitcher.tsx | 122 +++++++++--------- 1 file changed, 62 insertions(+), 60 deletions(-) diff --git a/src/components/views/settings/LayoutSwitcher.tsx b/src/components/views/settings/LayoutSwitcher.tsx index 4796519ee1..a96161d781 100644 --- a/src/components/views/settings/LayoutSwitcher.tsx +++ b/src/components/views/settings/LayoutSwitcher.tsx @@ -63,67 +63,69 @@ export default class LayoutSwitcher extends React.Component { mx_AppearanceUserSettingsTab_Layout_RadioButton_selected: this.state.layout === Layout.Bubble, }); - return
- - { _t("Message layout") } - + return ( +
+ + { _t("Message layout") } + -
- - - +
+ + + +
-
; + ); } } From 25c6b216b0976759d642f963b076bd0bb37b3d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 6 Aug 2021 10:37:42 +0200 Subject: [PATCH 3/5] Move LayoutSwitcher CSS to a separate file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- res/css/_components.scss | 1 + res/css/views/settings/_LayoutSwitcher.scss | 90 +++++++++++++++++++ .../tabs/user/_AppearanceUserSettingsTab.scss | 73 --------------- .../views/settings/LayoutSwitcher.tsx | 22 ++--- 4 files changed, 102 insertions(+), 84 deletions(-) create mode 100644 res/css/views/settings/_LayoutSwitcher.scss diff --git a/res/css/_components.scss b/res/css/_components.scss index 92d2bfe7f3..4bef7bf14a 100644 --- a/res/css/_components.scss +++ b/res/css/_components.scss @@ -240,6 +240,7 @@ @import "./views/settings/_E2eAdvancedPanel.scss"; @import "./views/settings/_EmailAddresses.scss"; @import "./views/settings/_IntegrationManager.scss"; +@import "./views/settings/_LayoutSwitcher.scss"; @import "./views/settings/_Notifications.scss"; @import "./views/settings/_PhoneNumbers.scss"; @import "./views/settings/_ProfileSettings.scss"; diff --git a/res/css/views/settings/_LayoutSwitcher.scss b/res/css/views/settings/_LayoutSwitcher.scss new file mode 100644 index 0000000000..1cf312f4d1 --- /dev/null +++ b/res/css/views/settings/_LayoutSwitcher.scss @@ -0,0 +1,90 @@ +/* +Copyright 2021 Šimon Brandner + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +.mx_LayoutSwitcher { + .mx_LayoutSwitcher_RadioButtons { + display: flex; + flex-direction: row; + gap: 24px; + + color: $primary-fg-color; + + > .mx_LayoutSwitcher_RadioButton { + flex-grow: 0; + flex-shrink: 1; + display: flex; + flex-direction: column; + + width: 300px; + + border: 1px solid $appearance-tab-border-color; + border-radius: 10px; + + .mx_EventTile_msgOption, + .mx_MessageActionBar { + display: none; + } + + .mx_LayoutSwitcher_RadioButton_preview { + flex-grow: 1; + display: flex; + align-items: center; + padding: 10px; + pointer-events: none; + } + + .mx_RadioButton { + flex-grow: 0; + padding: 10px; + } + + .mx_EventTile_content { + margin-right: 0; + } + + &.mx_LayoutSwitcher_RadioButton_selected { + border-color: $accent-color; + } + } + + .mx_RadioButton { + border-top: 1px solid $appearance-tab-border-color; + + > input + div { + border-color: rgba($muted-fg-color, 0.2); + } + } + + .mx_RadioButton_checked { + background-color: rgba($accent-color, 0.08); + } + + .mx_EventTile { + margin: 0; + &[data-layout=bubble] { + margin-right: 40px; + } + &[data-layout=irc] { + > a { + display: none; + } + } + .mx_EventTile_line { + max-width: 90%; + } + } + } +} diff --git a/res/css/views/settings/tabs/user/_AppearanceUserSettingsTab.scss b/res/css/views/settings/tabs/user/_AppearanceUserSettingsTab.scss index ca5a6f0a66..55124dfde1 100644 --- a/res/css/views/settings/tabs/user/_AppearanceUserSettingsTab.scss +++ b/res/css/views/settings/tabs/user/_AppearanceUserSettingsTab.scss @@ -155,79 +155,6 @@ limitations under the License. margin-left: calc($font-16px + 10px); } -.mx_AppearanceUserSettingsTab_Layout_RadioButtons { - display: flex; - flex-direction: row; - gap: 24px; - - color: $primary-fg-color; - - > .mx_AppearanceUserSettingsTab_Layout_RadioButton { - flex-grow: 0; - flex-shrink: 1; - display: flex; - flex-direction: column; - - width: 300px; - - border: 1px solid $appearance-tab-border-color; - border-radius: 10px; - - .mx_EventTile_msgOption, - .mx_MessageActionBar { - display: none; - } - - .mx_AppearanceUserSettingsTab_Layout_RadioButton_preview { - flex-grow: 1; - display: flex; - align-items: center; - padding: 10px; - pointer-events: none; - } - - .mx_RadioButton { - flex-grow: 0; - padding: 10px; - } - - .mx_EventTile_content { - margin-right: 0; - } - - &.mx_AppearanceUserSettingsTab_Layout_RadioButton_selected { - border-color: $accent-color; - } - } - - .mx_RadioButton { - border-top: 1px solid $appearance-tab-border-color; - - > input + div { - border-color: rgba($muted-fg-color, 0.2); - } - } - - .mx_RadioButton_checked { - background-color: rgba($accent-color, 0.08); - } - - .mx_EventTile { - margin: 0; - &[data-layout=bubble] { - margin-right: 40px; - } - &[data-layout=irc] { - > a { - display: none; - } - } - .mx_EventTile_line { - max-width: 90%; - } - } -} - .mx_AppearanceUserSettingsTab_Advanced { color: $primary-fg-color; diff --git a/src/components/views/settings/LayoutSwitcher.tsx b/src/components/views/settings/LayoutSwitcher.tsx index a96161d781..9afdf205f8 100644 --- a/src/components/views/settings/LayoutSwitcher.tsx +++ b/src/components/views/settings/LayoutSwitcher.tsx @@ -53,26 +53,26 @@ export default class LayoutSwitcher extends React.Component { }; public render(): JSX.Element { - const ircClasses = classNames("mx_AppearanceUserSettingsTab_Layout_RadioButton", { - mx_AppearanceUserSettingsTab_Layout_RadioButton_selected: this.state.layout == Layout.IRC, + const ircClasses = classNames("mx_LayoutSwitcher_RadioButton", { + mx_LayoutSwitcher_RadioButton_selected: this.state.layout == Layout.IRC, }); - const groupClasses = classNames("mx_AppearanceUserSettingsTab_Layout_RadioButton", { - mx_AppearanceUserSettingsTab_Layout_RadioButton_selected: this.state.layout == Layout.Group, + const groupClasses = classNames("mx_LayoutSwitcher_RadioButton", { + mx_LayoutSwitcher_RadioButton_selected: this.state.layout == Layout.Group, }); - const bubbleClasses = classNames("mx_AppearanceUserSettingsTab_Layout_RadioButton", { - mx_AppearanceUserSettingsTab_Layout_RadioButton_selected: this.state.layout === Layout.Bubble, + const bubbleClasses = classNames("mx_LayoutSwitcher_RadioButton", { + mx_LayoutSwitcher_RadioButton_selected: this.state.layout === Layout.Bubble, }); return ( -
+
{ _t("Message layout") } -
+