kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Mastodon: conditionally render emojiReacts
rodzic
893c903d71
commit
e5e15fc3f0
|
@ -2,6 +2,7 @@ import api from '../api';
|
||||||
import { importFetchedAccounts, importFetchedStatus } from './importer';
|
import { importFetchedAccounts, importFetchedStatus } from './importer';
|
||||||
import { favourite, unfavourite } from './interactions';
|
import { favourite, unfavourite } from './interactions';
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||||
|
import { List as ImmutableList } from 'immutable';
|
||||||
|
|
||||||
export const EMOJI_REACT_REQUEST = 'EMOJI_REACT_REQUEST';
|
export const EMOJI_REACT_REQUEST = 'EMOJI_REACT_REQUEST';
|
||||||
export const EMOJI_REACT_SUCCESS = 'EMOJI_REACT_SUCCESS';
|
export const EMOJI_REACT_SUCCESS = 'EMOJI_REACT_SUCCESS';
|
||||||
|
@ -19,7 +20,7 @@ const noOp = () => () => new Promise(f => f());
|
||||||
|
|
||||||
export const simpleEmojiReact = (status, emoji) => {
|
export const simpleEmojiReact = (status, emoji) => {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const emojiReacts = status.getIn(['pleroma', 'emoji_reactions']);
|
const emojiReacts = status.getIn(['pleroma', 'emoji_reactions'], ImmutableList());
|
||||||
|
|
||||||
if (emoji === '👍' && status.get('favourited')) return dispatch(unfavourite(status));
|
if (emoji === '👍' && status.get('favourited')) return dispatch(unfavourite(status));
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import EmojiSelector from 'soapbox/components/emoji_selector';
|
||||||
import { getReactForStatus, reduceEmoji } from 'soapbox/utils/emoji_reacts';
|
import { getReactForStatus, reduceEmoji } from 'soapbox/utils/emoji_reacts';
|
||||||
import { simpleEmojiReact } from 'soapbox/actions/emoji_reacts';
|
import { simpleEmojiReact } from 'soapbox/actions/emoji_reacts';
|
||||||
import { List as ImmutableList } from 'immutable';
|
import { List as ImmutableList } from 'immutable';
|
||||||
|
import { getFeatures } from 'soapbox/utils/features';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
delete: { id: 'status.delete', defaultMessage: 'Delete' },
|
delete: { id: 'status.delete', defaultMessage: 'Delete' },
|
||||||
|
@ -93,6 +94,7 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
allowedEmoji: ImmutablePropTypes.list,
|
allowedEmoji: ImmutablePropTypes.list,
|
||||||
emojiSelectorFocused: PropTypes.bool,
|
emojiSelectorFocused: PropTypes.bool,
|
||||||
handleEmojiSelectorUnfocus: PropTypes.func.isRequired,
|
handleEmojiSelectorUnfocus: PropTypes.func.isRequired,
|
||||||
|
features: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
@ -132,16 +134,26 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
isMobile = () => window.matchMedia('only screen and (max-width: 895px)').matches;
|
isMobile = () => window.matchMedia('only screen and (max-width: 895px)').matches;
|
||||||
|
|
||||||
handleLikeButtonHover = e => {
|
handleLikeButtonHover = e => {
|
||||||
if (!this.isMobile()) this.setState({ emojiSelectorVisible: true });
|
const { features } = this.props;
|
||||||
|
|
||||||
|
if (features.emojiReacts && !this.isMobile()) {
|
||||||
|
this.setState({ emojiSelectorVisible: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLikeButtonLeave = e => {
|
handleLikeButtonLeave = e => {
|
||||||
if (!this.isMobile()) this.setState({ emojiSelectorVisible: false });
|
const { features } = this.props;
|
||||||
|
|
||||||
|
if (features.emojiReacts && !this.isMobile()) {
|
||||||
|
this.setState({ emojiSelectorVisible: false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLikeButtonClick = e => {
|
handleLikeButtonClick = e => {
|
||||||
|
const { features } = this.props;
|
||||||
const meEmojiReact = getReactForStatus(this.props.status, this.props.allowedEmoji) || '👍';
|
const meEmojiReact = getReactForStatus(this.props.status, this.props.allowedEmoji) || '👍';
|
||||||
if (this.isMobile()) {
|
|
||||||
|
if (features.emojiReacts && this.isMobile()) {
|
||||||
if (this.state.emojiSelectorVisible) {
|
if (this.state.emojiSelectorVisible) {
|
||||||
this.handleReactClick(meEmojiReact)();
|
this.handleReactClick(meEmojiReact)();
|
||||||
} else {
|
} else {
|
||||||
|
@ -362,7 +374,7 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { status, intl, allowedEmoji, emojiSelectorFocused, handleEmojiSelectorUnfocus } = this.props;
|
const { status, intl, allowedEmoji, emojiSelectorFocused, handleEmojiSelectorUnfocus, features } = this.props;
|
||||||
const { emojiSelectorVisible } = this.state;
|
const { emojiSelectorVisible } = this.state;
|
||||||
|
|
||||||
const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
|
const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
|
||||||
|
@ -427,7 +439,7 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
>
|
>
|
||||||
<EmojiSelector
|
<EmojiSelector
|
||||||
onReact={this.handleReactClick}
|
onReact={this.handleReactClick}
|
||||||
visible={emojiSelectorVisible}
|
visible={features.emojiReacts && emojiSelectorVisible}
|
||||||
focused={emojiSelectorFocused}
|
focused={emojiSelectorFocused}
|
||||||
onUnfocus={handleEmojiSelectorUnfocus}
|
onUnfocus={handleEmojiSelectorUnfocus}
|
||||||
/>
|
/>
|
||||||
|
@ -456,11 +468,13 @@ class StatusActionBar extends ImmutablePureComponent {
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
const account = state.getIn(['accounts', me]);
|
const account = state.getIn(['accounts', me]);
|
||||||
|
const instance = state.get('instance');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
me,
|
me,
|
||||||
isStaff: account ? isStaff(account) : false,
|
isStaff: account ? isStaff(account) : false,
|
||||||
isAdmin: account ? isAdmin(account) : false,
|
isAdmin: account ? isAdmin(account) : false,
|
||||||
|
features: getFeatures(instance),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { isStaff, isAdmin } from 'soapbox/utils/accounts';
|
||||||
import { isUserTouching } from 'soapbox/is_mobile';
|
import { isUserTouching } from 'soapbox/is_mobile';
|
||||||
import EmojiSelector from 'soapbox/components/emoji_selector';
|
import EmojiSelector from 'soapbox/components/emoji_selector';
|
||||||
import { getReactForStatus } from 'soapbox/utils/emoji_reacts';
|
import { getReactForStatus } from 'soapbox/utils/emoji_reacts';
|
||||||
|
import { getFeatures } from 'soapbox/utils/features';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
delete: { id: 'status.delete', defaultMessage: 'Delete' },
|
delete: { id: 'status.delete', defaultMessage: 'Delete' },
|
||||||
|
@ -54,11 +55,13 @@ const messages = defineMessages({
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const me = state.get('me');
|
const me = state.get('me');
|
||||||
const account = state.getIn(['accounts', me]);
|
const account = state.getIn(['accounts', me]);
|
||||||
|
const instance = state.get('instance');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
me,
|
me,
|
||||||
isStaff: account ? isStaff(account) : false,
|
isStaff: account ? isStaff(account) : false,
|
||||||
isAdmin: account ? isAdmin(account) : false,
|
isAdmin: account ? isAdmin(account) : false,
|
||||||
|
features: getFeatures(instance),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,6 +106,7 @@ class ActionBar extends React.PureComponent {
|
||||||
emojiSelectorFocused: PropTypes.bool,
|
emojiSelectorFocused: PropTypes.bool,
|
||||||
handleEmojiSelectorExpand: PropTypes.func.isRequired,
|
handleEmojiSelectorExpand: PropTypes.func.isRequired,
|
||||||
handleEmojiSelectorUnfocus: PropTypes.func.isRequired,
|
handleEmojiSelectorUnfocus: PropTypes.func.isRequired,
|
||||||
|
features: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
@ -146,16 +150,26 @@ class ActionBar extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLikeButtonHover = e => {
|
handleLikeButtonHover = e => {
|
||||||
if (!isUserTouching()) this.setState({ emojiSelectorVisible: true });
|
const { features } = this.props;
|
||||||
|
|
||||||
|
if (features.emojiReacts && !isUserTouching()) {
|
||||||
|
this.setState({ emojiSelectorVisible: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLikeButtonLeave = e => {
|
handleLikeButtonLeave = e => {
|
||||||
if (!isUserTouching()) this.setState({ emojiSelectorVisible: false });
|
const { features } = this.props;
|
||||||
|
|
||||||
|
if (features.emojiReacts && !isUserTouching()) {
|
||||||
|
this.setState({ emojiSelectorVisible: false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLikeButtonClick = e => {
|
handleLikeButtonClick = e => {
|
||||||
|
const { features } = this.props;
|
||||||
const meEmojiReact = getReactForStatus(this.props.status, this.props.allowedEmoji) || '👍';
|
const meEmojiReact = getReactForStatus(this.props.status, this.props.allowedEmoji) || '👍';
|
||||||
if (isUserTouching()) {
|
|
||||||
|
if (features.emojiReacts && isUserTouching()) {
|
||||||
if (this.state.emojiSelectorVisible) {
|
if (this.state.emojiSelectorVisible) {
|
||||||
this.handleReactClick(meEmojiReact)();
|
this.handleReactClick(meEmojiReact)();
|
||||||
} else {
|
} else {
|
||||||
|
@ -278,7 +292,7 @@ class ActionBar extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { status, intl, me, isStaff, isAdmin, allowedEmoji, emojiSelectorFocused, handleEmojiSelectorExpand, handleEmojiSelectorUnfocus } = this.props;
|
const { status, intl, me, isStaff, isAdmin, allowedEmoji, emojiSelectorFocused, handleEmojiSelectorExpand, handleEmojiSelectorUnfocus, features } = this.props;
|
||||||
const { emojiSelectorVisible } = this.state;
|
const { emojiSelectorVisible } = this.state;
|
||||||
const ownAccount = status.getIn(['account', 'id']) === me;
|
const ownAccount = status.getIn(['account', 'id']) === me;
|
||||||
|
|
||||||
|
@ -391,7 +405,7 @@ class ActionBar extends React.PureComponent {
|
||||||
>
|
>
|
||||||
<EmojiSelector
|
<EmojiSelector
|
||||||
onReact={this.handleReactClick}
|
onReact={this.handleReactClick}
|
||||||
visible={emojiSelectorVisible}
|
visible={features.emojiReacts && emojiSelectorVisible}
|
||||||
focused={emojiSelectorFocused}
|
focused={emojiSelectorFocused}
|
||||||
onUnfocus={handleEmojiSelectorUnfocus}
|
onUnfocus={handleEmojiSelectorUnfocus}
|
||||||
/>
|
/>
|
||||||
|
|
Ładowanie…
Reference in New Issue