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

110 lines
3.1 KiB
JavaScript
Executable file

import React from 'react';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import Flux from '../lib/flux';
import ChannelPinsStore from '../stores/ChannelPinsStore';
import ChannelPinActionCreators from '../actions/ChannelPinActionCreators';
import i18n from '../i18n';
import MessageAlerts from './MessageAlerts';
import ReadStateStore from '../stores/ReadStateStore';
import MessagesPopout from './common/MessagesPopout';
import UserStore from '../stores/UserStore';
import {ThemeTypes, ChannelTypes} from '../Constants';
const ANALYTICS_NAME = 'Channel Pins';
const ChannelPins = React.createClass({
propTypes: {
channel: React.PropTypes.object.isRequired,
onJump: React.PropTypes.func,
},
mixins: [Flux.StoreListenerMixin(ChannelPinsStore, ReadStateStore), PureRenderMixin],
fetchPins(channel) {
ChannelPinActionCreators.ackPins(channel.id);
ChannelPinActionCreators.fetchPins(channel.id);
},
componentWillUpdate(nextProps, nextState) {
if (nextState.hasUnreadPins && !this.state.hasUnreadPins) {
ChannelPinActionCreators.ackPins(this.props.channel.id);
}
},
getStateFromStores() {
const pins = ChannelPinsStore.getPinnedMessages(this.props.channel.id);
const hasUnreadPins = ReadStateStore.hasUnreadPins(this.props.channel.id);
return {
messages: pins && pins.messages,
loading: !pins || !pins.messages || pins.loading,
hasUnreadPins,
};
},
handleUnpin(message, e) {
if (e.shiftKey) {
ChannelPinActionCreators.unpinMessage(this.props.channel, message.id);
} else {
MessageAlerts.confirmUnpin(this.props.channel, message);
}
},
getProTip() {
const {channel} = this.props;
let proTip = i18n.Messages.PINNED_MESSAGES_PRO_TIP_BODY_CHANNEL;
if (channel.isPrivate()) {
if (channel.type === ChannelTypes.DM) {
const other = UserStore.getUser(channel.getRecipientId()).username;
proTip = i18n.Messages.PINNED_MESSAGES_PRO_TIP_BODY_DM.format({other});
} else {
proTip = i18n.Messages.PINNED_MESSAGES_PRO_TIP_BODY_GROUP_DM;
}
}
return proTip;
},
renderEmptyState(theme) {
let msg = i18n.Messages.NO_PINS_IN_CHANNEL;
if (this.props.channel.isPrivate()) {
msg = i18n.Messages.NO_PINS_IN_DM;
}
const image = theme === ThemeTypes.LIGHT
? require('../images/empty-pin-light.svg')
: require('../images/empty-pins-dark.svg');
return <MessagesPopout.EmptyStateCenter msg={msg} image={image} />;
},
renderHeader() {
return <MessagesPopout.Header title={i18n.Messages.PINNED_MESSAGES} />;
},
render() {
const {messages, loading} = this.state;
return (
<MessagesPopout
onFetch={this.fetchPins}
channel={this.props.channel}
messages={messages}
loading={loading}
analyticsName={ANALYTICS_NAME}
onCloseMessage={this.handleUnpin}
onJump={this.props.onJump}
getProTip={this.getProTip}
renderHeader={this.renderHeader}
renderEmptyState={this.renderEmptyState}
/>
);
},
});
export default ChannelPins;
// WEBPACK FOOTER //
// ./discord_app/components/ChannelPins.js