kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Handle mobile emoji clicks (regular Status), use setRef
rodzic
4af3c453e6
commit
e9596fc191
|
@ -106,12 +106,27 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMobile = () => window.matchMedia('only screen and (max-width: 895px)').matches;
|
||||||
|
|
||||||
handleLikeButtonHover = e => {
|
handleLikeButtonHover = e => {
|
||||||
this.setState({ emojiSelectorVisible: true });
|
if (!this.isMobile()) this.setState({ emojiSelectorVisible: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLikeButtonLeave = e => {
|
handleLikeButtonLeave = e => {
|
||||||
this.setState({ emojiSelectorVisible: false });
|
if (!this.isMobile()) this.setState({ emojiSelectorVisible: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleLikeButtonClick = e => {
|
||||||
|
const meEmojiReact = getReactForStatus(this.props.status) || '👍';
|
||||||
|
if (this.isMobile()) {
|
||||||
|
if (this.state.emojiSelectorVisible) {
|
||||||
|
this.handleReactClick(meEmojiReact)();
|
||||||
|
} else {
|
||||||
|
this.setState({ emojiSelectorVisible: true });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.handleReactClick(meEmojiReact)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleReactClick = emoji => {
|
handleReactClick = emoji => {
|
||||||
|
@ -277,6 +292,17 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setRef = c => {
|
||||||
|
this.node = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
document.addEventListener('click', e => {
|
||||||
|
if (this.node && !this.node.contains(e.target))
|
||||||
|
this.setState({ emojiSelectorVisible: false });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { status, intl } = this.props;
|
const { status, intl } = this.props;
|
||||||
const { emojiSelectorVisible } = this.state;
|
const { emojiSelectorVisible } = this.state;
|
||||||
|
@ -330,6 +356,8 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
className='status__action-bar__counter status__action-bar__counter--favourite'
|
className='status__action-bar__counter status__action-bar__counter--favourite'
|
||||||
onMouseEnter={this.handleLikeButtonHover}
|
onMouseEnter={this.handleLikeButtonHover}
|
||||||
onMouseLeave={this.handleLikeButtonLeave}
|
onMouseLeave={this.handleLikeButtonLeave}
|
||||||
|
onClick={this.handleLikeButtonClick}
|
||||||
|
ref={this.setRef}
|
||||||
>
|
>
|
||||||
<EmojiSelector onReact={this.handleReactClick} visible={emojiSelectorVisible} />
|
<EmojiSelector onReact={this.handleReactClick} visible={emojiSelectorVisible} />
|
||||||
<IconButton
|
<IconButton
|
||||||
|
@ -339,7 +367,6 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
title={intl.formatMessage(messages.favourite)}
|
title={intl.formatMessage(messages.favourite)}
|
||||||
icon='thumbs-up'
|
icon='thumbs-up'
|
||||||
emoji={meEmojiReact}
|
emoji={meEmojiReact}
|
||||||
onClick={this.handleReactClick(meEmojiReact || '👍')}
|
|
||||||
/>
|
/>
|
||||||
{emojiReactCount !== 0 && <span className='detailed-status__link'>{emojiReactCount}</span>}
|
{emojiReactCount !== 0 && <span className='detailed-status__link'>{emojiReactCount}</span>}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -213,9 +213,13 @@ class ActionBar extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setRef = c => {
|
||||||
|
this.node = c;
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
document.addEventListener('click', e => {
|
document.addEventListener('click', e => {
|
||||||
if (!document.querySelector('.detailed-status__button--favourite').contains(e.target))
|
if (this.node && !this.node.contains(e.target))
|
||||||
this.setState({ emojiSelectorVisible: false });
|
this.setState({ emojiSelectorVisible: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -306,6 +310,7 @@ class ActionBar extends React.PureComponent {
|
||||||
onMouseEnter={this.handleLikeButtonHover}
|
onMouseEnter={this.handleLikeButtonHover}
|
||||||
onMouseLeave={this.handleLikeButtonLeave}
|
onMouseLeave={this.handleLikeButtonLeave}
|
||||||
onClick={this.handleLikeButtonClick}
|
onClick={this.handleLikeButtonClick}
|
||||||
|
ref={this.setRef}
|
||||||
>
|
>
|
||||||
<EmojiSelector onReact={this.handleReactClick} visible={emojiSelectorVisible} />
|
<EmojiSelector onReact={this.handleReactClick} visible={emojiSelectorVisible} />
|
||||||
<IconButton
|
<IconButton
|
||||||
|
|
Ładowanie…
Reference in New Issue