PLT-5511 Ability to flag and unflag posts (#360)
This commit is contained in:
parent
74db04f672
commit
e61f6264ac
2 changed files with 24 additions and 8 deletions
|
|
@ -43,6 +43,7 @@ class Post extends PureComponent {
|
|||
displayName: PropTypes.string,
|
||||
renderReplies: PropTypes.bool,
|
||||
isFirstReply: PropTypes.bool,
|
||||
isFlagged: PropTypes.bool,
|
||||
isLastReply: PropTypes.bool,
|
||||
commentedOnDisplayName: PropTypes.string,
|
||||
commentedOnPost: PropTypes.object,
|
||||
|
|
@ -51,7 +52,9 @@ class Post extends PureComponent {
|
|||
onPress: PropTypes.func,
|
||||
actions: PropTypes.shape({
|
||||
deletePost: PropTypes.func.isRequired,
|
||||
goToUserProfile: PropTypes.func.isRequired
|
||||
flagPost: PropTypes.func.isRequired,
|
||||
goToUserProfile: PropTypes.func.isRequired,
|
||||
unflagPost: PropTypes.func.isRequired
|
||||
}).isRequired
|
||||
};
|
||||
|
||||
|
|
@ -172,14 +175,23 @@ class Post extends PureComponent {
|
|||
|
||||
renderMessage = (style, messageStyle, replyBar = false) => {
|
||||
const {formatMessage} = this.props.intl;
|
||||
const {currentUserId, post, roles, theme} = this.props;
|
||||
const {currentUserId, isFlagged, post, roles, theme} = this.props;
|
||||
const {flagPost, unflagPost} = this.props.actions;
|
||||
const actions = [];
|
||||
|
||||
// we should check for the user roles and permissions
|
||||
// actions.push({text: 'Flag', onPress: () => console.log('flag pressed')}); //eslint-disable-line no-console
|
||||
// if (post.user_id === currentUserId) {
|
||||
// actions.push({text: 'Edit', onPress: () => console.log('edit pressed')}); //eslint-disable-line no-console
|
||||
// }
|
||||
if (isFlagged) {
|
||||
actions.push({
|
||||
text: formatMessage({id: 'post_info.mobile.unflag', defaultMessage: 'Unflag'}),
|
||||
onPress: () => unflagPost(post.id)
|
||||
});
|
||||
} else {
|
||||
actions.push({
|
||||
text: formatMessage({id: 'post_info.mobile.flag', defaultMessage: 'Flag'}),
|
||||
onPress: () => flagPost(post.id)
|
||||
});
|
||||
}
|
||||
|
||||
if (post.user_id === currentUserId || isAdmin(roles)) {
|
||||
actions.push({text: formatMessage({id: 'post_info.del', defaultMessage: 'Delete'}), onPress: () => this.handlePostDelete()});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ import {bindActionCreators} from 'redux';
|
|||
import {goToUserProfile} from 'app/actions/navigation';
|
||||
import {getTheme} from 'app/selectors/preferences';
|
||||
|
||||
import {deletePost} from 'mattermost-redux/actions/posts';
|
||||
import {deletePost, flagPost, unflagPost} from 'mattermost-redux/actions/posts';
|
||||
import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences';
|
||||
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
|
||||
import {getCurrentUserId, getCurrentUserRoles, getUser} from 'mattermost-redux/selectors/entities/users';
|
||||
import {isPostFlagged} from 'mattermost-redux/utils/post_utils';
|
||||
import {displayUsername} from 'mattermost-redux/utils/user_utils';
|
||||
|
||||
import Post from './post';
|
||||
|
|
@ -26,6 +27,7 @@ function mapStateToProps(state, ownProps) {
|
|||
currentTeamId: getCurrentTeamId(state),
|
||||
currentUserId: getCurrentUserId(state),
|
||||
displayName: displayUsername(user, myPreferences),
|
||||
isFlagged: isPostFlagged(ownProps.post.id, myPreferences),
|
||||
roles: getCurrentUserRoles(state),
|
||||
theme: getTheme(state),
|
||||
user,
|
||||
|
|
@ -37,7 +39,9 @@ function mapDispatchToProps(dispatch) {
|
|||
return {
|
||||
actions: bindActionCreators({
|
||||
deletePost,
|
||||
goToUserProfile
|
||||
flagPost,
|
||||
goToUserProfile,
|
||||
unflagPost
|
||||
}, dispatch)
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue