sforkowany z mirror/soapbox
profile card basic functionality, needs some UI improvements
rodzic
563e4e5bab
commit
f6ebe5cbd7
|
@ -1,4 +1,5 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import VerificationBadge from './verification_badge';
|
||||
import { acctFull } from '../utils/accounts';
|
||||
|
@ -8,10 +9,11 @@ export default class DisplayName extends React.PureComponent {
|
|||
static propTypes = {
|
||||
account: ImmutablePropTypes.map.isRequired,
|
||||
others: ImmutablePropTypes.list,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
render() {
|
||||
const { account, others } = this.props;
|
||||
const { account, others, children } = this.props;
|
||||
|
||||
let displayName, suffix;
|
||||
|
||||
|
@ -40,6 +42,7 @@ export default class DisplayName extends React.PureComponent {
|
|||
<span className='display-name'>
|
||||
{displayName}
|
||||
{suffix}
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ import classNames from 'classnames';
|
|||
import Icon from 'soapbox/components/icon';
|
||||
import PollContainer from 'soapbox/containers/poll_container';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import UserPanel from '../features/ui/components/user_panel';
|
||||
import ProfileHoverCardContainer from '../features/profile_hover_card/profile_hover_card_container';
|
||||
import { isMobile } from '../../../app/soapbox/is_mobile';
|
||||
|
||||
// We use the component (and not the container) since we do not want
|
||||
// to use the progress bar to show download progress
|
||||
|
@ -105,9 +106,7 @@ class Status extends ImmutablePureComponent {
|
|||
state = {
|
||||
showMedia: defaultMediaVisibility(this.props.status, this.props.displayMedia),
|
||||
statusId: undefined,
|
||||
profilePanelVisible: false,
|
||||
profilePanelX: 0,
|
||||
profilePanelY: 0,
|
||||
profileCardVisible: false,
|
||||
};
|
||||
|
||||
// Track height changes we know about to compensate scrolling
|
||||
|
@ -253,14 +252,12 @@ class Status extends ImmutablePureComponent {
|
|||
this.handleToggleMediaVisibility();
|
||||
}
|
||||
|
||||
isMobile = () => window.matchMedia('only screen and (max-width: 895px)').matches;
|
||||
|
||||
handleProfileHover = e => {
|
||||
if (!this.isMobile()) this.setState({ profilePanelVisible: true, profilePanelX: e.nativeEvent.offsetX, profilePanelY: e.nativeEvent.offsetY });
|
||||
if (!isMobile()) this.setState({ profileCardVisible: true });
|
||||
}
|
||||
|
||||
handleProfileLeave = e => {
|
||||
if (!this.isMobile()) this.setState({ profilePanelVisible: false });
|
||||
if (!isMobile()) this.setState({ profileCardVisible: false });
|
||||
}
|
||||
|
||||
_properStatus() {
|
||||
|
@ -449,7 +446,7 @@ class Status extends ImmutablePureComponent {
|
|||
};
|
||||
|
||||
const statusUrl = `/@${status.getIn(['account', 'acct'])}/posts/${status.get('id')}`;
|
||||
const { profilePanelVisible, profilePanelX, profilePanelY } = this.state;
|
||||
const { profileCardVisible } = this.state;
|
||||
|
||||
return (
|
||||
<HotKeys handlers={handlers}>
|
||||
|
@ -468,9 +465,10 @@ class Status extends ImmutablePureComponent {
|
|||
<div className='status__avatar'>
|
||||
{statusAvatar}
|
||||
</div>
|
||||
<DisplayName account={status.get('account')} others={otherAccounts} />
|
||||
</NavLink>
|
||||
<UserPanel accountId={status.getIn(['account', 'id'])} visible={profilePanelVisible} style={{ top: `${profilePanelY+15}px`, left: `${profilePanelX-132}px` }} />
|
||||
<DisplayName account={status.get('account')} others={otherAccounts}>
|
||||
<ProfileHoverCardContainer accountId={status.getIn(['account', 'id'])} visible={profileCardVisible} />
|
||||
</DisplayName>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
onMuteNotifications(account, notifications) {
|
||||
dispatch(muteAccount(account.get('id'), notifications));
|
||||
},
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { makeGetAccount } from '../../selectors';
|
||||
import { injectIntl, FormattedMessage } from 'react-intl';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import UserPanel from '../ui/components/user_panel';
|
||||
import ActionButton from '../ui/components/action_button';
|
||||
import { isAdmin, isModerator } from 'soapbox/utils/accounts';
|
||||
import Badge from 'soapbox/components/badge';
|
||||
|
||||
const getAccount = makeGetAccount();
|
||||
|
||||
const mapStateToProps = (state, { accountId }) => {
|
||||
return {
|
||||
account: getAccount(state, accountId),
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
|
||||
});
|
||||
|
||||
export default @connect(mapStateToProps, mapDispatchToProps)
|
||||
@injectIntl
|
||||
class ProfileHoverCardContainer extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
visible: PropTypes.bool,
|
||||
accountId: PropTypes.string,
|
||||
account: ImmutablePropTypes.map,
|
||||
intl: PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
visible: true,
|
||||
}
|
||||
|
||||
render() {
|
||||
const { visible, accountId, account } = this.props;
|
||||
if (!accountId) return null;
|
||||
const accountBio = { __html: account.get('note_emojified') };
|
||||
let followed_by = account.getIn(['relationship', 'followed_by']);
|
||||
|
||||
return visible && (
|
||||
<div className='profile-hover-card'>
|
||||
<div className='profile-hover-card__container'>
|
||||
<div className='profile-hover-card__action-button'><ActionButton account={account} /></div>
|
||||
<UserPanel className='profile-hover-card__user' accountId={accountId} />
|
||||
<div className='profile-hover-card__badges'>
|
||||
{isAdmin(account) && <Badge slug='admin' title='Admin' />}
|
||||
{isModerator(account) && <Badge slug='moderator' title='Moderator' />}
|
||||
{account.getIn(['patron', 'is_patron']) && <Badge slug='patron' title='Patron' />}
|
||||
{ followed_by ?
|
||||
<span className='relationship-tag'>
|
||||
<FormattedMessage id='account.follows_you' defaultMessage='Follows you' />
|
||||
</span>
|
||||
: '' }
|
||||
</div>
|
||||
<div className='profile-hover-card__bio' dangerouslySetInnerHTML={accountBio} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
};
|
|
@ -0,0 +1,98 @@
|
|||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import PropTypes from 'prop-types';
|
||||
import { defineMessages, injectIntl } from 'react-intl';
|
||||
import Button from 'soapbox/components/button';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
followAccount,
|
||||
unfollowAccount,
|
||||
blockAccount,
|
||||
unblockAccount,
|
||||
} from 'soapbox/actions/accounts';
|
||||
|
||||
const messages = defineMessages({
|
||||
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
|
||||
follow: { id: 'account.follow', defaultMessage: 'Follow' },
|
||||
requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' },
|
||||
unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
|
||||
edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
|
||||
});
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const me = state.get('me');
|
||||
return {
|
||||
me,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
onFollow(account) {
|
||||
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
|
||||
dispatch(unfollowAccount(account.get('id')));
|
||||
} else {
|
||||
dispatch(followAccount(account.get('id')));
|
||||
}
|
||||
},
|
||||
|
||||
onBlock(account) {
|
||||
if (account.getIn(['relationship', 'blocking'])) {
|
||||
dispatch(unblockAccount(account.get('id')));
|
||||
} else {
|
||||
dispatch(blockAccount(account.get('id')));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default @connect(mapStateToProps, mapDispatchToProps)
|
||||
@injectIntl
|
||||
class ActionButton extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
account: ImmutablePropTypes.map.isRequired,
|
||||
onFollow: PropTypes.func.isRequired,
|
||||
onBlock: PropTypes.func.isRequired,
|
||||
intl: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
window.addEventListener('resize', this.handleResize, { passive: true });
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener('resize', this.handleResize);
|
||||
}
|
||||
|
||||
handleFollow = () => {
|
||||
this.props.onFollow(this.props.account);
|
||||
}
|
||||
|
||||
handleBlock = () => {
|
||||
this.props.onBlock(this.props.account);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { account, intl, me } = this.props;
|
||||
let actionBtn = null;
|
||||
|
||||
if (!account || !me) return actionBtn;
|
||||
|
||||
if (me !== account.get('id')) {
|
||||
if (!account.get('relationship')) { // Wait until the relationship is loaded
|
||||
//
|
||||
} else if (account.getIn(['relationship', 'requested'])) {
|
||||
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.requested)} onClick={this.handleFollow} />;
|
||||
} else if (!account.getIn(['relationship', 'blocking'])) {
|
||||
actionBtn = <Button disabled={account.getIn(['relationship', 'blocked_by'])} className={classNames('logo-button', { 'button--destructive': account.getIn(['relationship', 'following']) })} text={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.handleFollow} />;
|
||||
} else if (account.getIn(['relationship', 'blocking'])) {
|
||||
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.handleBlock} />;
|
||||
}
|
||||
} else {
|
||||
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.edit_profile)} to='/settings/profile' />;
|
||||
}
|
||||
return actionBtn;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,22 +19,20 @@ class UserPanel extends ImmutablePureComponent {
|
|||
intl: PropTypes.object.isRequired,
|
||||
domain: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
visible: PropTypes.bool,
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
style: {},
|
||||
visible: true,
|
||||
}
|
||||
|
||||
render() {
|
||||
const { account, intl, domain, style, visible } = this.props;
|
||||
const { account, intl, domain, style } = this.props;
|
||||
if (!account) return null;
|
||||
const displayNameHtml = { __html: account.get('display_name_html') };
|
||||
const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct');
|
||||
|
||||
return (
|
||||
<div className={classNames('user-panel', { 'user-panel--visible': visible })} style={style}>
|
||||
<div className={classNames('user-panel')} style={style}>
|
||||
<div className='user-panel__container'>
|
||||
|
||||
<div className='user-panel__header'>
|
||||
|
|
|
@ -71,3 +71,4 @@
|
|||
@import 'components/error-boundary';
|
||||
@import 'components/video-player';
|
||||
@import 'components/audio-player';
|
||||
@import 'components/profile_hover_card';
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
.display-name__account {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.profile-hover-card {
|
||||
@include standard-panel;
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
transition-property: opacity;
|
||||
transition-duration: 0.5s;
|
||||
z-index: 998;
|
||||
opacity: 1;
|
||||
transition-delay: 1s;
|
||||
left: -10px;
|
||||
|
||||
@media(min-width: 750px) {
|
||||
left: -80px;
|
||||
}
|
||||
|
||||
.profile-hover-card__container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.profile-hover-card__action-button {
|
||||
z-index: 999;
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
top: 120px;
|
||||
}
|
||||
|
||||
.user-panel {
|
||||
box-shadow: none;
|
||||
|
||||
.user-panel-stats-item a strong {
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.profile-hover-card__badges {
|
||||
margin: 0 20px 20px;
|
||||
display: flex;
|
||||
|
||||
.badge, .relationship-tag {
|
||||
padding: 2px 4px;
|
||||
margin-right: 5px;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
.profile-hover-card__bio {
|
||||
margin: 0 20px 20px;
|
||||
}
|
||||
}
|
|
@ -162,22 +162,6 @@
|
|||
.status__profile,
|
||||
.detailed-status__profile {
|
||||
display: inline-block;
|
||||
|
||||
.user-panel {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition-property: opacity;
|
||||
transition-duration: 0.5s;
|
||||
z-index: 999;
|
||||
|
||||
&--visible {
|
||||
opacity: 1;
|
||||
transition-delay: 1s;
|
||||
pointer-events: all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.status-check-box {
|
||||
|
|
Ładowanie…
Reference in New Issue