mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-16 08:31:31 +03:00
d5db67be38
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
/*
|
|
Copyright 2017 New Vector Ltd
|
|
|
|
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 PropTypes from 'prop-types';
|
|
import createReactClass from 'create-react-class';
|
|
import sdk from '../../../index';
|
|
import GroupStore from '../../../stores/GroupStore';
|
|
import ToggleSwitch from "../elements/ToggleSwitch";
|
|
|
|
export default createReactClass({
|
|
displayName: 'GroupPublicityToggle',
|
|
|
|
propTypes: {
|
|
groupId: PropTypes.string.isRequired,
|
|
},
|
|
|
|
getInitialState() {
|
|
return {
|
|
busy: false,
|
|
ready: false,
|
|
isGroupPublicised: null,
|
|
};
|
|
},
|
|
|
|
componentWillMount: function() {
|
|
this._initGroupStore(this.props.groupId);
|
|
},
|
|
|
|
_initGroupStore: function(groupId) {
|
|
this._groupStoreToken = GroupStore.registerListener(groupId, () => {
|
|
this.setState({
|
|
isGroupPublicised: GroupStore.getGroupPublicity(groupId),
|
|
ready: GroupStore.isStateReady(groupId, GroupStore.STATE_KEY.Summary),
|
|
});
|
|
});
|
|
},
|
|
|
|
componentWillUnmount() {
|
|
if (this._groupStoreToken) this._groupStoreToken.unregister();
|
|
},
|
|
|
|
_onPublicityToggle: function() {
|
|
this.setState({
|
|
busy: true,
|
|
// Optimistic early update
|
|
isGroupPublicised: !this.state.isGroupPublicised,
|
|
});
|
|
GroupStore.setGroupPublicity(this.props.groupId, !this.state.isGroupPublicised).then(() => {
|
|
this.setState({
|
|
busy: false,
|
|
});
|
|
});
|
|
},
|
|
|
|
render() {
|
|
const GroupTile = sdk.getComponent('groups.GroupTile');
|
|
return <div className="mx_GroupPublicity_toggle">
|
|
<GroupTile groupId={this.props.groupId} showDescription={false}
|
|
avatarHeight={40} draggable={false}
|
|
/>
|
|
<ToggleSwitch checked={this.state.isGroupPublicised}
|
|
disabled={!this.state.ready || this.state.busy}
|
|
onChange={this._onPublicityToggle} />
|
|
</div>;
|
|
},
|
|
});
|