import React from 'react'; import Flux from '../lib/flux'; import UserGuildSettingsStore from '../stores/UserGuildSettingsStore'; import Radio from './common/Radio'; import {UserNotificationSettings} from '../Constants'; import i18n from '../i18n'; import NotificationSettingsModalActionCreators from '../actions/NotificationSettingsModalActionCreators'; import ChannelMuteButton from './ChannelMuteButton'; import '../styles/channel_notification_settings.styl'; const ChannelNotificationSettings = React.createClass({ mixins: [Flux.StoreListenerMixin(UserGuildSettingsStore)], getStateFromStores() { return { messageNotifications: UserGuildSettingsStore.getChannelMessageNotifications( this.props.channel.getGuildId(), this.props.channel.id ), muted: UserGuildSettingsStore.isChannelMuted(this.props.channel.getGuildId(), this.props.channel.id), guildMessageNotifications: UserGuildSettingsStore.getMessageNotifications(this.props.channel.getGuildId()), }; }, handleRadioChange(key, e) { NotificationSettingsModalActionCreators.updateChannelOverrideSettings( this.props.channel.getGuildId(), this.props.channel.id, {[key]: parseInt(e.currentTarget.value, 10)} ); }, handleReset() { NotificationSettingsModalActionCreators.updateChannelOverrideSettings( this.props.channel.getGuildId(), this.props.channel.id, { // eslint-disable-next-line camelcase message_notifications: UserNotificationSettings.NULL, } ); }, messageNotificationsRadioOption(value) { const {messageNotifications, muted, guildMessageNotifications} = this.state; let checked = false; let isDefault = false; if (messageNotifications === UserNotificationSettings.NULL) { isDefault = guildMessageNotifications === value; } else { checked = messageNotifications === value; } return (
); }, render() { const {messageNotifications} = this.state; const muted = this.state.muted || this.props.guildMuted; let reset; let options; if (!muted) { if (messageNotifications !== UserNotificationSettings.NULL) { reset = (
{i18n.Messages.RESET}
); } options = (
{this.messageNotificationsRadioOption(UserNotificationSettings.ALL_MESSAGES)} {this.messageNotificationsRadioOption(UserNotificationSettings.ONLY_MENTIONS)} {this.messageNotificationsRadioOption(UserNotificationSettings.NO_MESSAGES)}
); } return (
{reset}
{options}
); }, }); export default ChannelNotificationSettings; // WEBPACK FOOTER // // ./discord_app/components/ChannelNotificationSettings.js