diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-06-15 07:45:46 +0800 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-06-14 19:45:46 -0400 |
commit | 0e89d9be1d6a2a1ca470f9ca92e0d59e5945ca18 (patch) | |
tree | 2fbfd8bc9f30e6ac84bcb14cc8c4c0a5e566be24 /webapp/components/dot_menu/dot_menu_flag.jsx | |
parent | 5b017171cd42872a11a9c8b3e2e8bb9bd29c2b3a (diff) | |
download | chat-0e89d9be1d6a2a1ca470f9ca92e0d59e5945ca18.tar.gz chat-0e89d9be1d6a2a1ca470f9ca92e0d59e5945ca18.tar.bz2 chat-0e89d9be1d6a2a1ca470f9ca92e0d59e5945ca18.zip |
create DotMenu components and add dotmenu IDs to posts at center and RHS (#6642)
Diffstat (limited to 'webapp/components/dot_menu/dot_menu_flag.jsx')
-rw-r--r-- | webapp/components/dot_menu/dot_menu_flag.jsx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/webapp/components/dot_menu/dot_menu_flag.jsx b/webapp/components/dot_menu/dot_menu_flag.jsx new file mode 100644 index 000000000..105363211 --- /dev/null +++ b/webapp/components/dot_menu/dot_menu_flag.jsx @@ -0,0 +1,70 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import React from 'react'; +import {FormattedMessage} from 'react-intl'; +import PropTypes from 'prop-types'; + +import {flagPost, unflagPost} from 'actions/post_actions.jsx'; +import * as Utils from 'utils/utils.jsx'; +import Constants from 'utils/constants.jsx'; + +function formatMessage(isFlagged) { + return ( + <FormattedMessage + id={isFlagged ? 'rhs_root.mobile.unflag' : 'rhs_root.mobile.flag'} + defaultMessage={isFlagged ? 'Unflag' : 'Flag'} + /> + ); +} + +export default function DotMenuFlag(props) { + function onFlagPost(e) { + e.preventDefault(); + flagPost(props.postId); + } + + function onUnflagPost(e) { + e.preventDefault(); + unflagPost(props.postId); + } + + const flagFunc = props.isFlagged ? onUnflagPost : onFlagPost; + + let flagId = null; + if (props.idCount > -1) { + flagId = Utils.createSafeId(props.idPrefix + props.idCount); + } + + if (props.idPrefix.indexOf(Constants.RHS_ROOT) === 0) { + flagId = props.idPrefix; + } + + return ( + <li + key={props.idPrefix} + role='presentation' + > + <a + id={flagId} + href='#' + onClick={flagFunc} + > + {formatMessage(props.isFlagged)} + </a> + </li> + ); +} + +DotMenuFlag.propTypes = { + idCount: PropTypes.number, + idPrefix: PropTypes.string.isRequired, + postId: PropTypes.string.isRequired, + isFlagged: PropTypes.bool.isRequired +}; + +DotMenuFlag.defaultProps = { + idCount: -1, + postId: '', + isFlagged: false +}; |