mirror of https://github.com/vector-im/riot-web
Convert RoomPublishSetting and LabelledToggleSwitch to Typescript
parent
9454a4e6c7
commit
8d4ac90265
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 New Vector Ltd
|
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -14,38 +14,33 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import ToggleSwitch from "./ToggleSwitch";
|
import ToggleSwitch from "./ToggleSwitch";
|
||||||
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
// The value for the toggle switch
|
||||||
|
value: boolean;
|
||||||
|
// The translated label for the switch
|
||||||
|
label: string;
|
||||||
|
// Whether or not to disable the toggle switch
|
||||||
|
disabled?: boolean;
|
||||||
|
// True to put the toggle in front of the label
|
||||||
|
// Default false.
|
||||||
|
toggleInFront?: boolean;
|
||||||
|
// Additional class names to append to the switch. Optional.
|
||||||
|
className?: string;
|
||||||
|
// The function to call when the value changes
|
||||||
|
onChange(checked: boolean): void;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.elements.LabelledToggleSwitch")
|
@replaceableComponent("views.elements.LabelledToggleSwitch")
|
||||||
export default class LabelledToggleSwitch extends React.Component {
|
export default class LabelledToggleSwitch extends React.PureComponent<IProps> {
|
||||||
static propTypes = {
|
|
||||||
// The value for the toggle switch
|
|
||||||
value: PropTypes.bool.isRequired,
|
|
||||||
|
|
||||||
// The function to call when the value changes
|
|
||||||
onChange: PropTypes.func.isRequired,
|
|
||||||
|
|
||||||
// The translated label for the switch
|
|
||||||
label: PropTypes.string.isRequired,
|
|
||||||
|
|
||||||
// Whether or not to disable the toggle switch
|
|
||||||
disabled: PropTypes.bool,
|
|
||||||
|
|
||||||
// True to put the toggle in front of the label
|
|
||||||
// Default false.
|
|
||||||
toggleInFront: PropTypes.bool,
|
|
||||||
|
|
||||||
// Additional class names to append to the switch. Optional.
|
|
||||||
className: PropTypes.string,
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
// This is a minimal version of a SettingsFlag
|
// This is a minimal version of a SettingsFlag
|
||||||
|
|
||||||
let firstPart = <span className="mx_SettingsFlag_label">{this.props.label}</span>;
|
let firstPart = <span className="mx_SettingsFlag_label">{ this.props.label }</span>;
|
||||||
let secondPart = <ToggleSwitch
|
let secondPart = <ToggleSwitch
|
||||||
checked={this.props.value}
|
checked={this.props.value}
|
||||||
disabled={this.props.disabled}
|
disabled={this.props.disabled}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -14,20 +14,30 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from "react";
|
||||||
|
|
||||||
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
|
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
|
||||||
import {_t} from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||||
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
roomId: string;
|
||||||
|
label?: string;
|
||||||
|
canSetCanonicalAlias?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IState {
|
||||||
|
isRoomPublished: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.room_settings.RoomPublishSetting")
|
@replaceableComponent("views.room_settings.RoomPublishSetting")
|
||||||
export default class RoomPublishSetting extends React.PureComponent {
|
export default class RoomPublishSetting extends React.PureComponent<IProps, IState> {
|
||||||
constructor(props) {
|
public state = {
|
||||||
super(props);
|
isRoomPublished: false,
|
||||||
this.state = {isRoomPublished: false};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
onRoomPublishChange = (e) => {
|
private onRoomPublishChange = (e) => {
|
||||||
const valueBefore = this.state.isRoomPublished;
|
const valueBefore = this.state.isRoomPublished;
|
||||||
const newValue = !valueBefore;
|
const newValue = !valueBefore;
|
||||||
this.setState({isRoomPublished: newValue});
|
this.setState({isRoomPublished: newValue});
|
||||||
|
@ -52,11 +62,14 @@ export default class RoomPublishSetting extends React.PureComponent {
|
||||||
render() {
|
render() {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
|
|
||||||
return (<LabelledToggleSwitch value={this.state.isRoomPublished}
|
return (
|
||||||
onChange={this.onRoomPublishChange}
|
<LabelledToggleSwitch value={this.state.isRoomPublished}
|
||||||
disabled={!this.props.canSetCanonicalAlias}
|
onChange={this.onRoomPublishChange}
|
||||||
label={_t("Publish this room to the public in %(domain)s's room directory?", {
|
disabled={!this.props.canSetCanonicalAlias}
|
||||||
domain: client.getDomain(),
|
label={_t("Publish this room to the public in %(domain)s's room directory?", {
|
||||||
})} />);
|
domain: client.getDomain(),
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue