From 47884616f7fd3f7c7cfa95885fb9132e689da354 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Tue, 21 May 2024 00:46:17 +0200 Subject: [PATCH] [Glitch+Emoji reactions] Use modern React context for for identity for emoji reaction code --- CHANGELOG.md | 1 + .../flavours/glitch/components/status.jsx | 28 +++++++++---------- .../status/components/detailed_status.jsx | 11 +++----- .../flavours/glitch/features/status/index.jsx | 4 +-- .../features/ui/util/identity_consumer.jsx | 16 ----------- 5 files changed, 21 insertions(+), 39 deletions(-) delete mode 100644 app/javascript/flavours/glitch/features/ui/util/identity_consumer.jsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c0cf90b56..090525bc0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All changes to Catstodon that aren't Mastodon or glitch-soc Mastodon changes wil - Upstream changes, once again (including, but not limited to:) - Only uses a maximum of 1 megabyte of response body for link previews - Allow multiple `redirect_uri`s for OAuth 2.0 Applications +- Adjust emoji reactions patch to use modern React context for identity instead of an identity consumer ## [v4.3.0-alpha.3+glitch+cat+1.2.2] - 2024-05-17 diff --git a/app/javascript/flavours/glitch/components/status.jsx b/app/javascript/flavours/glitch/components/status.jsx index 0faa6d1dbd..eb8f55338a 100644 --- a/app/javascript/flavours/glitch/components/status.jsx +++ b/app/javascript/flavours/glitch/components/status.jsx @@ -3,15 +3,18 @@ import PropTypes from 'prop-types'; import { injectIntl, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; +import { withRouter } from 'react-router-dom'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; +import { connect } from 'react-redux'; import { HotKeys } from 'react-hotkeys'; import PictureInPicturePlaceholder from 'flavours/glitch/components/picture_in_picture_placeholder'; import PollContainer from 'flavours/glitch/containers/poll_container'; import NotificationOverlayContainer from 'flavours/glitch/features/notifications/containers/overlay_container'; +import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context'; import { autoUnfoldCW } from 'flavours/glitch/utils/content_warning'; import { withOptionalRouter, WithOptionalRouterPropTypes } from 'flavours/glitch/utils/react_router'; @@ -20,7 +23,6 @@ import Card from '../features/status/components/card'; // to use the progress bar to show download progress import Bundle from '../features/ui/components/bundle'; import { MediaGallery, Video, Audio } from '../features/ui/util/async-components'; -import { IdentityConsumer } from '../features/ui/util/identity_consumer'; import { SensitiveMediaContext } from '../features/ui/util/sensitive_media_context'; import { displayMedia, visibleReactions } from '../initial_state'; @@ -78,6 +80,7 @@ class Status extends ImmutablePureComponent { static contextType = SensitiveMediaContext; static propTypes = { + identity: identityContextPropShape, containerId: PropTypes.string, id: PropTypes.string, status: ImmutablePropTypes.map, @@ -545,6 +548,7 @@ class Status extends ImmutablePureComponent { nextInReplyToId, rootId, history, + identity, ...other } = this.props; const { isCollapsed } = this.state; @@ -846,18 +850,14 @@ class Status extends ImmutablePureComponent { {...statusContentProps} /> - - {identity => ( - - )} - + {(!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar']))) && (
@@ -348,4 +345,4 @@ class DetailedStatus extends ImmutablePureComponent { } -export default withRouter(DetailedStatus); +export default withRouter(withIdentity(DetailedStatus)); diff --git a/app/javascript/flavours/glitch/features/status/index.jsx b/app/javascript/flavours/glitch/features/status/index.jsx index 95d33f2afb..57852b3b2c 100644 --- a/app/javascript/flavours/glitch/features/status/index.jsx +++ b/app/javascript/flavours/glitch/features/status/index.jsx @@ -307,8 +307,8 @@ class Status extends ImmutablePureComponent { }; handleReactionAdd = (statusId, name, url) => { - const { dispatch } = this.props; - const { signedIn } = this.context.identity; + const { dispatch, identity } = this.props; + const { signedIn } = identity.signedIn; if (signedIn) { dispatch(addReaction(statusId, name, url)); diff --git a/app/javascript/flavours/glitch/features/ui/util/identity_consumer.jsx b/app/javascript/flavours/glitch/features/ui/util/identity_consumer.jsx deleted file mode 100644 index bf7c7e70f9..0000000000 --- a/app/javascript/flavours/glitch/features/ui/util/identity_consumer.jsx +++ /dev/null @@ -1,16 +0,0 @@ -import PropTypes from 'prop-types'; -import { PureComponent } from 'react'; - -export class IdentityConsumer extends PureComponent { - static contextTypes = { - identity: PropTypes.object - }; - - static propTypes = { - children: PropTypes.func.isRequired - }; - - render() { - return this.props.children(this.context.identity); - } -}