const bindAll = require('lodash.bindall');
const FormattedMessage = require('react-intl').FormattedMessage;
const FormattedNumber = require('react-intl').FormattedNumber;
const injectIntl = require('react-intl').injectIntl;
const intlShape = require('react-intl').intlShape;
const PropTypes = require('prop-types');
const React = require('react');
const Button = require('../../components/forms/button.jsx');
const FlexRow = require('../../components/flex-row/flex-row.jsx');
const Form = require('../../components/forms/form.jsx');
const Select = require('../../components/forms/select.jsx');
const TitleBanner = require('../../components/title-banner/title-banner.jsx');
const messageStatuses = require('../../redux/messages').Status;
// Message Components
const AdminMessage = require('./message-rows/admin-message.jsx');
const BecomeManagerMessage = require('./message-rows/become-manager.jsx');
const CommentMessage = require('./message-rows/comment-message.jsx');
const CuratorInviteMessage = require('./message-rows/curator-invite.jsx');
const FavoriteProjectMessage = require('./message-rows/favorite-project.jsx');
const FollowUserMessage = require('./message-rows/follow-user.jsx');
const ForumPostMessage = require('./message-rows/forum-topic-post.jsx');
const LoveProjectMessage = require('./message-rows/love-project.jsx');
const RemixProjectMessage = require('./message-rows/remix-project.jsx');
const ScratcherInvite = require('./message-rows/scratcher-invite.jsx');
const StudioActivityMessage = require('./message-rows/studio-activity.jsx');
const UserJoinMessage = require('./message-rows/user-join.jsx');
require('./messages.scss');
class SocialMessagesList extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'getComponentForMessage',
'renderLoadMore',
'renderMessageCounter'
]);
}
getComponentForMessage (message, unread) {
const className = (unread) ? 'mod-unread' : '';
const key = `${message.type}_ ${message.id}`;
switch (message.type) {
case 'followuser':
return (
);
case 'loveproject':
return (
);
case 'favoriteproject':
return (
);
case 'addcomment':
return (
);
case 'curatorinvite':
return (
);
case 'remixproject':
return (
);
case 'studioactivity':
return (
);
case 'forumpost':
return (
);
case 'becomeownerstudio':
return (
);
case 'userjoin':
return (
);
}
}
renderLoadMore (loadMore) {
if (loadMore) {
return (
);
}
return null;
}
renderMessageCounter (numNewMessages) {
if (numNewMessages > 0) {
return (
);
}
return null;
}
render () {
if (this.props.loadStatus === messageStatuses.MESSAGES_ERROR) {
return (
);
}
return (
{this.props.messages.length > 0 ? [
{this.renderMessageCounter(this.props.numNewMessages)}
,
{this.props.messages.map((message, messageId) => {
if (messageId < this.props.numNewMessages) {
return this.getComponentForMessage(message, true);
}
return this.getComponentForMessage(message, false);
})}
] : []}
{this.renderLoadMore(this.props.loadMore)}
);
}
}
SocialMessagesList.propTypes = {
loadMore: PropTypes.bool.isRequired,
loadStatus: PropTypes.string,
messages: PropTypes.arrayOf(PropTypes.object).isRequired,
numNewMessages: PropTypes.number,
onLoadMoreMethod: PropTypes.func
};
SocialMessagesList.defaultProps = {
loadStatus: messageStatuses.FETCHING,
numNewMessages: 0
};
const MessagesPresentation = props => {
let adminMessageLength = props.adminMessages.length;
if (Object.keys(props.scratcherInvite).length > 0) {
adminMessageLength = adminMessageLength + 1;
}
let numNewSocialMessages = props.numNewMessages - adminMessageLength;
if (numNewSocialMessages < 0) {
numNewSocialMessages = 0;
}
return (
{props.adminMessages.length > 0 || Object.keys(props.scratcherInvite).length > 0 ? [
{Object.keys(props.scratcherInvite).length > 0 ? [
{ // eslint-disable-line react/jsx-no-bind
props.onAdminDismiss('invite', props.scratcherInvite.id);
}}
/>
] : []}
{props.adminMessages.map(item => (
{ // eslint-disable-line react/jsx-no-bind
props.onAdminDismiss('notification', item.id);
}}
/>
))}
] : []}
{props.requestStatus.admin === messageStatuses.ADMIN_ERROR ? [
] : []}
);
};
MessagesPresentation.propTypes = {
adminMessages: PropTypes.arrayOf(PropTypes.object).isRequired,
filter: PropTypes.string,
intl: intlShape,
loadMore: PropTypes.bool.isRequired,
messages: PropTypes.arrayOf(PropTypes.object).isRequired,
numNewMessages: PropTypes.number,
onAdminDismiss: PropTypes.func.isRequired,
onFilterClick: PropTypes.func.isRequired,
onLoadMoreMethod: PropTypes.func,
requestStatus: PropTypes.shape({
admin: PropTypes.string,
clear: PropTypes.string,
message: PropTypes.string,
delete: PropTypes.string
}).isRequired,
scratcherInvite: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
user: PropTypes.shape({
id: PropTypes.number,
banned: PropTypes.bool,
username: PropTypes.string,
token: PropTypes.string,
thumbnailUrl: PropTypes.string,
dateJoined: PropTypes.string,
email: PropTypes.string,
classroomId: PropTypes.string
}).isRequired
};
MessagesPresentation.defaultProps = {
filter: '',
filterOpen: false,
numNewMessages: 0
};
module.exports = injectIntl(MessagesPresentation);