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

81 lines
2.2 KiB
JavaScript
Executable file

/* @flow */
import React from 'react';
import Flux from '../lib/flux';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import ChannelNoticesStore from '../stores/ChannelNoticesStore';
import GuildMFAWarning from './channel_notices/GuildMFAWarning';
import {showNotice} from '../actions/ChannelNoticeActionCreators';
import InviteNotice from './channel_notices/InviteNotice';
import QuickSwitcherNotice from './channel_notices/QuickSwitcherNotice';
import ChannelNoticeRegistry from '../lib/ChannelNoticeRegistry';
import AppAnalyticsUtils from '../utils/AppAnalyticsUtils';
import {AnalyticEvents} from '../Constants';
import '../styles/channel_notices.styl';
const NOTICE_REGISTRY = new ChannelNoticeRegistry([GuildMFAWarning, InviteNotice, QuickSwitcherNotice]);
const ChannelNotices = React.createClass({
mixins: [PureRenderMixin, Flux.LazyStoreListenerMixin(ChannelNoticesStore, ...NOTICE_REGISTRY.getStores())],
propTypes: {
guild: React.PropTypes.object.isRequired,
},
getInitialState() {
return this.getStateFromStores();
},
getStateFromStores() {
const channelStoreState = ChannelNoticesStore.getState();
const {noticeStates, lastHidden} = channelStoreState;
const {guild} = this.props;
return {
...channelStoreState,
Notice: NOTICE_REGISTRY.getNotice(noticeStates, guild, lastHidden),
};
},
componentDidMount() {
const {guild} = this.props;
const {Notice} = this.state;
if (Notice != null) {
showNotice(Notice.Type, guild);
}
},
componentDidUpdate() {
const {guild} = this.props;
const {Notice} = this.state;
if (Notice != null) {
showNotice(Notice.Type, guild);
}
},
render() {
const {guild} = this.props;
const {Notice} = this.state;
if (Notice == null) {
return null;
}
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.CHANNEL_NOTICE_VIEWED, {
// eslint-disable-next-line camelcase
notice_type: Notice.Type,
});
return (
<div className="channel-notices">
<Notice guild={guild} />
</div>
);
},
});
export default ChannelNotices;
// WEBPACK FOOTER //
// ./discord_app/components/ChannelNotices.js