2020-04-14 16:19:50 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2019 New Vector Ltd
|
2021-08-06 10:40:26 +02:00
|
|
|
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
|
2020-04-14 16:19:50 +01:00
|
|
|
|
|
|
|
|
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';
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../../../languageHandler";
|
2020-07-10 19:07:11 +01:00
|
|
|
import SdkConfig from "../../../../../SdkConfig";
|
2021-02-26 16:02:46 -05:00
|
|
|
import { MatrixClientPeg } from '../../../../../MatrixClientPeg';
|
2020-07-28 11:53:43 -06:00
|
|
|
import SettingsStore from "../../../../../settings/SettingsStore";
|
2020-06-18 13:58:35 +01:00
|
|
|
import StyledCheckbox from '../../../elements/StyledCheckbox';
|
|
|
|
|
import SettingsFlag from '../../../elements/SettingsFlag';
|
2020-06-22 15:35:48 +01:00
|
|
|
import Field from '../../../elements/Field';
|
2020-07-28 11:53:43 -06:00
|
|
|
import { SettingLevel } from "../../../../../settings/SettingLevel";
|
2021-06-02 10:42:17 +01:00
|
|
|
import { UIFeature } from "../../../../../settings/UIFeature";
|
|
|
|
|
import { Layout } from "../../../../../settings/Layout";
|
|
|
|
|
import { replaceableComponent } from "../../../../../utils/replaceableComponent";
|
2021-08-06 10:27:18 +02:00
|
|
|
import LayoutSwitcher from "../../LayoutSwitcher";
|
2020-04-14 16:19:50 +01:00
|
|
|
|
2021-10-19 14:50:09 +01:00
|
|
|
import FontScalingPanel from '../../FontScalingPanel';
|
2021-10-20 15:58:27 +01:00
|
|
|
import ThemeChoicePanel from '../../ThemeChoicePanel';
|
2021-10-15 16:30:53 +02:00
|
|
|
|
2020-05-28 13:55:07 +01:00
|
|
|
interface IProps {
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 09:59:34 +01:00
|
|
|
interface IState {
|
2020-06-22 11:39:11 +01:00
|
|
|
useSystemFont: boolean;
|
|
|
|
|
systemFont: string;
|
|
|
|
|
showAdvanced: boolean;
|
2021-01-22 13:44:45 +01:00
|
|
|
layout: Layout;
|
2021-02-26 16:02:46 -05:00
|
|
|
// User profile data for the message preview
|
2021-08-27 19:32:38 +02:00
|
|
|
userId?: string;
|
2021-02-26 16:02:46 -05:00
|
|
|
displayName: string;
|
|
|
|
|
avatarUrl: string;
|
2020-05-28 13:55:07 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-08 20:20:07 -07:00
|
|
|
@replaceableComponent("views.settings.tabs.user.AppearanceUserSettingsTab")
|
2020-05-28 13:55:07 +01:00
|
|
|
export default class AppearanceUserSettingsTab extends React.Component<IProps, IState> {
|
2020-06-18 15:47:26 +01:00
|
|
|
private readonly MESSAGE_PREVIEW_TEXT = _t("Hey you. You're the best!");
|
2020-05-28 13:55:07 +01:00
|
|
|
|
2021-07-15 12:10:54 +01:00
|
|
|
private unmounted = false;
|
2020-05-28 13:55:07 +01:00
|
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
|
super(props);
|
2020-04-14 16:19:50 +01:00
|
|
|
|
|
|
|
|
this.state = {
|
2020-06-15 15:33:52 +01:00
|
|
|
useSystemFont: SettingsStore.getValue("useSystemFont"),
|
|
|
|
|
systemFont: SettingsStore.getValue("systemFont"),
|
|
|
|
|
showAdvanced: false,
|
2021-01-22 13:44:45 +01:00
|
|
|
layout: SettingsStore.getValue("layout"),
|
2021-08-27 19:23:26 +02:00
|
|
|
userId: null,
|
|
|
|
|
displayName: null,
|
2021-02-26 16:02:46 -05:00
|
|
|
avatarUrl: null,
|
2020-04-16 11:56:43 +01:00
|
|
|
};
|
2020-04-14 16:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-26 16:02:46 -05:00
|
|
|
async componentDidMount() {
|
|
|
|
|
// Fetch the current user profile for the message preview
|
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
|
const userId = client.getUserId();
|
|
|
|
|
const profileInfo = await client.getProfileInfo(userId);
|
2021-07-15 12:10:54 +01:00
|
|
|
if (this.unmounted) return;
|
2021-02-26 16:02:46 -05:00
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
userId,
|
|
|
|
|
displayName: profileInfo.displayname,
|
|
|
|
|
avatarUrl: profileInfo.avatar_url,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-15 12:10:54 +01:00
|
|
|
componentWillUnmount() {
|
|
|
|
|
this.unmounted = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-06 10:27:18 +02:00
|
|
|
private onLayoutChanged = (layout: Layout): void => {
|
2021-06-17 14:11:44 +01:00
|
|
|
this.setState({ layout: layout });
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-22 13:44:45 +01:00
|
|
|
private onIRCLayoutChange = (enabled: boolean) => {
|
|
|
|
|
if (enabled) {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ layout: Layout.IRC });
|
2021-01-22 13:44:45 +01:00
|
|
|
SettingsStore.setValue("layout", null, SettingLevel.DEVICE, Layout.IRC);
|
|
|
|
|
} else {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ layout: Layout.Group });
|
2021-01-22 13:44:45 +01:00
|
|
|
SettingsStore.setValue("layout", null, SettingLevel.DEVICE, Layout.Group);
|
|
|
|
|
}
|
2021-06-29 13:11:58 +01:00
|
|
|
};
|
2021-01-22 13:44:45 +01:00
|
|
|
|
2020-06-22 15:35:48 +01:00
|
|
|
private renderAdvancedSection() {
|
2020-09-18 11:34:35 +01:00
|
|
|
if (!SettingsStore.getValue(UIFeature.AdvancedSettings)) return null;
|
|
|
|
|
|
2020-07-14 18:04:29 +01:00
|
|
|
const brand = SdkConfig.get().brand;
|
2020-06-15 15:33:52 +01:00
|
|
|
const toggle = <div
|
|
|
|
|
className="mx_AppearanceUserSettingsTab_AdvancedToggle"
|
2021-06-29 13:11:58 +01:00
|
|
|
onClick={() => this.setState({ showAdvanced: !this.state.showAdvanced })}
|
2020-06-15 15:33:52 +01:00
|
|
|
>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ this.state.showAdvanced ? _t("Hide advanced") : _t("Show advanced") }
|
2020-06-15 15:33:52 +01:00
|
|
|
</div>;
|
|
|
|
|
|
|
|
|
|
let advanced: React.ReactNode;
|
|
|
|
|
|
|
|
|
|
if (this.state.showAdvanced) {
|
2020-07-14 18:04:29 +01:00
|
|
|
const tooltipContent = _t(
|
|
|
|
|
"Set the name of a font installed on your system & %(brand)s will attempt to use it.",
|
|
|
|
|
{ brand },
|
|
|
|
|
);
|
2020-06-24 16:06:50 +01:00
|
|
|
advanced = <>
|
|
|
|
|
<SettingsFlag
|
|
|
|
|
name="useCompactLayout"
|
|
|
|
|
level={SettingLevel.DEVICE}
|
|
|
|
|
useCheckbox={true}
|
2021-06-17 14:11:44 +01:00
|
|
|
disabled={this.state.layout !== Layout.Group}
|
2020-07-09 15:54:44 +01:00
|
|
|
/>
|
2021-06-17 14:11:44 +01:00
|
|
|
|
|
|
|
|
{ !SettingsStore.getValue("feature_new_layout_switcher") ?
|
|
|
|
|
<StyledCheckbox
|
|
|
|
|
checked={this.state.layout == Layout.IRC}
|
|
|
|
|
onChange={(ev) => this.onIRCLayoutChange(ev.target.checked)}
|
|
|
|
|
>
|
2021-07-20 11:08:13 +01:00
|
|
|
{ _t("Enable experimental, compact IRC style layout") }
|
2021-06-17 14:11:44 +01:00
|
|
|
</StyledCheckbox> : null
|
|
|
|
|
}
|
2021-01-22 13:44:45 +01:00
|
|
|
|
2020-06-15 15:33:52 +01:00
|
|
|
<SettingsFlag
|
|
|
|
|
name="useSystemFont"
|
|
|
|
|
level={SettingLevel.DEVICE}
|
|
|
|
|
useCheckbox={true}
|
2021-06-29 13:11:58 +01:00
|
|
|
onChange={(checked) => this.setState({ useSystemFont: checked })}
|
2020-06-15 15:33:52 +01:00
|
|
|
/>
|
|
|
|
|
<Field
|
|
|
|
|
className="mx_AppearanceUserSettingsTab_systemFont"
|
|
|
|
|
label={SettingsStore.getDisplayName("systemFont")}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
systemFont: value.target.value,
|
2020-06-22 11:39:11 +01:00
|
|
|
});
|
2020-06-15 15:33:52 +01:00
|
|
|
|
|
|
|
|
SettingsStore.setValue("systemFont", null, SettingLevel.DEVICE, value.target.value);
|
|
|
|
|
}}
|
2020-07-14 18:04:29 +01:00
|
|
|
tooltipContent={tooltipContent}
|
2020-06-15 17:42:30 +01:00
|
|
|
forceTooltipVisible={true}
|
2020-06-15 15:33:52 +01:00
|
|
|
disabled={!this.state.useSystemFont}
|
|
|
|
|
value={this.state.systemFont}
|
|
|
|
|
/>
|
2020-06-24 16:06:50 +01:00
|
|
|
</>;
|
2020-06-15 15:33:52 +01:00
|
|
|
}
|
|
|
|
|
return <div className="mx_SettingsTab_section mx_AppearanceUserSettingsTab_Advanced">
|
2021-07-19 22:43:11 +01:00
|
|
|
{ toggle }
|
|
|
|
|
{ advanced }
|
2020-06-22 11:39:11 +01:00
|
|
|
</div>;
|
2020-06-15 15:33:52 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:55:07 +01:00
|
|
|
render() {
|
2020-07-10 19:07:11 +01:00
|
|
|
const brand = SdkConfig.get().brand;
|
|
|
|
|
|
2021-08-06 10:27:18 +02:00
|
|
|
let layoutSection;
|
|
|
|
|
if (SettingsStore.getValue("feature_new_layout_switcher")) {
|
|
|
|
|
layoutSection = (
|
|
|
|
|
<LayoutSwitcher
|
|
|
|
|
userId={this.state.userId}
|
|
|
|
|
displayName={this.state.displayName}
|
|
|
|
|
avatarUrl={this.state.avatarUrl}
|
|
|
|
|
messagePreviewText={this.MESSAGE_PREVIEW_TEXT}
|
|
|
|
|
onLayoutChanged={this.onLayoutChanged}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:55:07 +01:00
|
|
|
return (
|
2020-06-11 12:27:09 +01:00
|
|
|
<div className="mx_SettingsTab mx_AppearanceUserSettingsTab">
|
2021-07-19 22:43:11 +01:00
|
|
|
<div className="mx_SettingsTab_heading">{ _t("Customise your appearance") }</div>
|
2020-06-08 18:17:02 +01:00
|
|
|
<div className="mx_SettingsTab_SubHeading">
|
2021-07-19 22:43:11 +01:00
|
|
|
{ _t("Appearance Settings only affect this %(brand)s session.", { brand }) }
|
2020-06-08 18:17:02 +01:00
|
|
|
</div>
|
2021-10-20 15:58:27 +01:00
|
|
|
<ThemeChoicePanel />
|
2021-08-06 10:27:18 +02:00
|
|
|
{ layoutSection }
|
2021-10-19 14:50:09 +01:00
|
|
|
<FontScalingPanel />
|
2021-07-19 22:43:11 +01:00
|
|
|
{ this.renderAdvancedSection() }
|
2020-05-28 13:55:07 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-04-14 16:19:50 +01:00
|
|
|
}
|