forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_reaction.tsx
More file actions
115 lines (100 loc) · 4 KB
/
Copy pathpost_reaction.tsx
File metadata and controls
115 lines (100 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import classNames from 'classnames';
import React from 'react';
import type {WrappedComponentProps} from 'react-intl';
import {defineMessages, injectIntl} from 'react-intl';
import type {Emoji} from '@mattermost/types/emojis';
import Permissions from 'mattermost-redux/constants/permissions';
import {getEmojiName} from 'mattermost-redux/utils/emoji_utils';
import EmojiPickerOverlay from 'components/emoji_picker/emoji_picker_overlay';
import ChannelPermissionGate from 'components/permissions_gates/channel_permission_gate';
import EmojiIcon from 'components/widgets/icons/emoji_icon';
import WithTooltip from 'components/with_tooltip';
import {Locations} from 'utils/constants';
const TOP_OFFSET = -7;
const messages = defineMessages({
addReaction: {
id: 'post_info.tooltip.add_reactions',
defaultMessage: 'Add Reaction',
},
});
export type Props = WrappedComponentProps & {
channelId?: string;
postId: string;
teamId: string;
getDotMenuRef: () => HTMLUListElement | null;
location?: keyof typeof Locations;
showEmojiPicker: boolean;
toggleEmojiPicker: (e?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
actions: {
toggleReaction: (postId: string, emojiName: string) => void;
};
}
type State = {
location: keyof typeof Locations;
showEmojiPicker: boolean;
}
export class PostReaction extends React.PureComponent<Props, State> {
public static defaultProps: Partial<Props> = {
location: Locations.CENTER as 'CENTER',
showEmojiPicker: false,
};
handleToggleEmoji = (emoji: Emoji): void => {
this.setState({showEmojiPicker: false});
const emojiName = getEmojiName(emoji);
this.props.actions.toggleReaction(this.props.postId, emojiName);
this.props.toggleEmojiPicker();
};
render() {
const {
channelId,
location,
postId,
showEmojiPicker,
teamId,
intl,
} = this.props;
let spaceRequiredAbove;
let spaceRequiredBelow;
if (location === Locations.RHS_ROOT || location === Locations.RHS_COMMENT) {
spaceRequiredAbove = EmojiPickerOverlay.RHS_SPACE_REQUIRED_ABOVE;
spaceRequiredBelow = EmojiPickerOverlay.RHS_SPACE_REQUIRED_BELOW;
}
return (
<ChannelPermissionGate
channelId={channelId}
teamId={teamId}
permissions={[Permissions.ADD_REACTION]}
>
<>
<EmojiPickerOverlay
show={showEmojiPicker}
target={this.props.getDotMenuRef}
onHide={this.props.toggleEmojiPicker}
onEmojiClick={this.handleToggleEmoji}
topOffset={TOP_OFFSET}
spaceRequiredAbove={spaceRequiredAbove}
spaceRequiredBelow={spaceRequiredBelow}
/>
<WithTooltip
title={messages.addReaction}
>
<button
data-testid='post-reaction-emoji-icon'
id={`${location}_reaction_${postId}`}
aria-label={intl.formatMessage({id: 'post_info.tooltip.add_reactions', defaultMessage: 'Add Reaction'})}
className={classNames('post-menu__item', 'post-menu__item--reactions', {
'post-menu__item--active': showEmojiPicker,
})}
onClick={this.props.toggleEmojiPicker}
>
<EmojiIcon className='icon icon--small'/>
</button>
</WithTooltip>
</>
</ChannelPermissionGate>
);
}
}
export default injectIntl(PostReaction);