[Glitch+Emoji reactions] Use modern React context for for identity for emoji reaction code
This commit is contained in:
parent
48b9837ad8
commit
6c28810b39
4 changed files with 18 additions and 39 deletions
|
@ -12,6 +12,7 @@ import { HotKeys } from 'react-hotkeys';
|
||||||
import PictureInPicturePlaceholder from 'flavours/glitch/components/picture_in_picture_placeholder';
|
import PictureInPicturePlaceholder from 'flavours/glitch/components/picture_in_picture_placeholder';
|
||||||
import PollContainer from 'flavours/glitch/containers/poll_container';
|
import PollContainer from 'flavours/glitch/containers/poll_container';
|
||||||
import NotificationOverlayContainer from 'flavours/glitch/features/notifications/containers/overlay_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 { autoUnfoldCW } from 'flavours/glitch/utils/content_warning';
|
||||||
import { withOptionalRouter, WithOptionalRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
import { withOptionalRouter, WithOptionalRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
||||||
|
|
||||||
|
@ -20,7 +21,6 @@ import Card from '../features/status/components/card';
|
||||||
// to use the progress bar to show download progress
|
// to use the progress bar to show download progress
|
||||||
import Bundle from '../features/ui/components/bundle';
|
import Bundle from '../features/ui/components/bundle';
|
||||||
import { MediaGallery, Video, Audio } from '../features/ui/util/async-components';
|
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 { SensitiveMediaContext } from '../features/ui/util/sensitive_media_context';
|
||||||
import { displayMedia, visibleReactions } from '../initial_state';
|
import { displayMedia, visibleReactions } from '../initial_state';
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ class Status extends ImmutablePureComponent {
|
||||||
static contextType = SensitiveMediaContext;
|
static contextType = SensitiveMediaContext;
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
identity: identityContextPropShape,
|
||||||
containerId: PropTypes.string,
|
containerId: PropTypes.string,
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
status: ImmutablePropTypes.map,
|
status: ImmutablePropTypes.map,
|
||||||
|
@ -545,6 +546,7 @@ class Status extends ImmutablePureComponent {
|
||||||
nextInReplyToId,
|
nextInReplyToId,
|
||||||
rootId,
|
rootId,
|
||||||
history,
|
history,
|
||||||
|
identity,
|
||||||
...other
|
...other
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { isCollapsed } = this.state;
|
const { isCollapsed } = this.state;
|
||||||
|
@ -846,18 +848,14 @@ class Status extends ImmutablePureComponent {
|
||||||
{...statusContentProps}
|
{...statusContentProps}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<IdentityConsumer>
|
<StatusReactions
|
||||||
{identity => (
|
statusId={status.get('id')}
|
||||||
<StatusReactions
|
reactions={status.get('reactions')}
|
||||||
statusId={status.get('id')}
|
numVisible={visibleReactions}
|
||||||
reactions={status.get('reactions')}
|
addReaction={this.props.onReactionAdd}
|
||||||
numVisible={visibleReactions}
|
removeReaction={this.props.onReactionRemove}
|
||||||
addReaction={this.props.onReactionAdd}
|
canReact={this.props.identity.signedIn}
|
||||||
removeReaction={this.props.onReactionRemove}
|
/>
|
||||||
canReact={identity.signedIn}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</IdentityConsumer>
|
|
||||||
|
|
||||||
{(!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar']))) && (
|
{(!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar']))) && (
|
||||||
<StatusActionBar
|
<StatusActionBar
|
||||||
|
@ -881,4 +879,4 @@ class Status extends ImmutablePureComponent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withOptionalRouter(injectIntl(Status));
|
export default withOptionalRouter(injectIntl((withIdentity(Status))));
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { getHashtagBarForStatus } from 'flavours/glitch/components/hashtag_bar';
|
||||||
import PictureInPicturePlaceholder from 'flavours/glitch/components/picture_in_picture_placeholder';
|
import PictureInPicturePlaceholder from 'flavours/glitch/components/picture_in_picture_placeholder';
|
||||||
import { VisibilityIcon } from 'flavours/glitch/components/visibility_icon';
|
import { VisibilityIcon } from 'flavours/glitch/components/visibility_icon';
|
||||||
import PollContainer from 'flavours/glitch/containers/poll_container';
|
import PollContainer from 'flavours/glitch/containers/poll_container';
|
||||||
|
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';
|
||||||
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
||||||
|
|
||||||
import { Avatar } from '../../../components/avatar';
|
import { Avatar } from '../../../components/avatar';
|
||||||
|
@ -29,12 +30,8 @@ import Video from '../../video';
|
||||||
import Card from './card';
|
import Card from './card';
|
||||||
|
|
||||||
class DetailedStatus extends ImmutablePureComponent {
|
class DetailedStatus extends ImmutablePureComponent {
|
||||||
|
|
||||||
static contextTypes = {
|
|
||||||
identity: PropTypes.object,
|
|
||||||
};
|
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
identity: identityContextPropShape,
|
||||||
status: ImmutablePropTypes.map,
|
status: ImmutablePropTypes.map,
|
||||||
settings: ImmutablePropTypes.map.isRequired,
|
settings: ImmutablePropTypes.map.isRequired,
|
||||||
onOpenMedia: PropTypes.func.isRequired,
|
onOpenMedia: PropTypes.func.isRequired,
|
||||||
|
@ -319,7 +316,7 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
reactions={status.get('reactions')}
|
reactions={status.get('reactions')}
|
||||||
addReaction={this.props.onReactionAdd}
|
addReaction={this.props.onReactionAdd}
|
||||||
removeReaction={this.props.onReactionRemove}
|
removeReaction={this.props.onReactionRemove}
|
||||||
canReact={this.context.identity.signedIn}
|
canReact={this.props.identity.signedIn}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className='detailed-status__meta'>
|
<div className='detailed-status__meta'>
|
||||||
|
@ -348,4 +345,4 @@ class DetailedStatus extends ImmutablePureComponent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withRouter(DetailedStatus);
|
export default withRouter(withIdentity(DetailedStatus));
|
||||||
|
|
|
@ -307,8 +307,8 @@ class Status extends ImmutablePureComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
handleReactionAdd = (statusId, name, url) => {
|
handleReactionAdd = (statusId, name, url) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch, identity } = this.props;
|
||||||
const { signedIn } = this.context.identity;
|
const { signedIn } = identity;
|
||||||
|
|
||||||
if (signedIn) {
|
if (signedIn) {
|
||||||
dispatch(addReaction(statusId, name, url));
|
dispatch(addReaction(statusId, name, url));
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue