2017-06-08_509bba0/509bba0_unpacked_with_node_modules/discord_app/components/ChannelMuteButton.js
2022-07-26 10:06:20 -07:00

79 lines
2.3 KiB
JavaScript
Executable file

import React from 'react';
import classNames from 'classnames';
import Flux from '../lib/flux';
import Tooltip from './common/Tooltip';
import {HeaderToolbarButton} from './HeaderToolbar';
import UserGuildSettingsStore from '../stores/UserGuildSettingsStore';
import NotificationSettingsModalActionCreators from '../actions/NotificationSettingsModalActionCreators';
import i18n from '../i18n';
import '../styles/channel_mute_button.styl';
const ChannelMuteButton = React.createClass({
mixins: [Flux.StoreListenerMixin(UserGuildSettingsStore)],
propTypes: {
channel: React.PropTypes.object.isRequired,
legacy: React.PropTypes.bool,
},
getDefaultProps() {
return {
legacy: false,
};
},
getStateFromStores() {
return {
isMuted: UserGuildSettingsStore.isChannelMuted(this.props.channel.getGuildId(), this.props.channel.id),
};
},
componentWillReceiveProps(nextProps) {
this.setState({
isMuted: UserGuildSettingsStore.isChannelMuted(nextProps.channel.getGuildId(), nextProps.channel.id),
});
},
handleClick() {
NotificationSettingsModalActionCreators.updateChannelOverrideSettings(
this.props.channel.getGuildId(),
this.props.channel.id,
{muted: !this.state.isMuted}
);
},
render() {
if (this.props.legacy) {
return (
<Tooltip text={i18n.Messages.CHANNEL_MUTE_TOOLTIP} position={Tooltip.BOTTOM}>
<span className={classNames('channel-mute-button', {muted: this.state.isMuted})} onClick={this.handleClick} />
</Tooltip>
);
} else {
let iconLight;
let iconDark;
if (this.state.isMuted) {
iconLight = require('../images/header_icons/ic_muted_grey_24px.svg');
iconDark = require('../images/icon-header-muted-dark.svg');
} else {
iconLight = require('../images/header_icons/ic_mute_grey_24px.svg');
iconDark = require('../images/icon-header-mute-dark.svg');
}
return (
<HeaderToolbarButton
onClick={this.handleClick}
tooltip={i18n.Messages.CHANNEL_MUTE_TOOLTIP}
iconLight={iconLight}
iconDark={iconDark}
/>
);
}
},
});
export default ChannelMuteButton;
// WEBPACK FOOTER //
// ./discord_app/components/ChannelMuteButton.js