Merge branch 'profile-hover-cards' into 'develop'

Profile hover cards

See merge request soapbox-pub/soapbox-fe!114
This commit is contained in:
Alex Gleason 2020-08-03 02:27:14 +00:00
commit 2c010768e9
16 changed files with 357 additions and 54 deletions

View file

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import VerificationBadge from './verification_badge'; import VerificationBadge from './verification_badge';
import { acctFull } from '../utils/accounts'; import { acctFull } from '../utils/accounts';
@ -8,10 +9,11 @@ export default class DisplayName extends React.PureComponent {
static propTypes = { static propTypes = {
account: ImmutablePropTypes.map.isRequired, account: ImmutablePropTypes.map.isRequired,
others: ImmutablePropTypes.list, others: ImmutablePropTypes.list,
children: PropTypes.node,
}; };
render() { render() {
const { account, others } = this.props; const { account, others, children } = this.props;
let displayName, suffix; let displayName, suffix;
@ -40,6 +42,7 @@ export default class DisplayName extends React.PureComponent {
<span className='display-name'> <span className='display-name'>
{displayName} {displayName}
{suffix} {suffix}
{children}
</span> </span>
); );
} }

View file

@ -18,6 +18,8 @@ import classNames from 'classnames';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import PollContainer from 'soapbox/containers/poll_container'; import PollContainer from 'soapbox/containers/poll_container';
import { NavLink } from 'react-router-dom'; import { NavLink } from 'react-router-dom';
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 // We use the component (and not the container) since we do not want
// to use the progress bar to show download progress // to use the progress bar to show download progress
@ -104,6 +106,7 @@ class Status extends ImmutablePureComponent {
state = { state = {
showMedia: defaultMediaVisibility(this.props.status, this.props.displayMedia), showMedia: defaultMediaVisibility(this.props.status, this.props.displayMedia),
statusId: undefined, statusId: undefined,
profileCardVisible: false,
}; };
// Track height changes we know about to compensate scrolling // Track height changes we know about to compensate scrolling
@ -249,6 +252,14 @@ class Status extends ImmutablePureComponent {
this.handleToggleMediaVisibility(); this.handleToggleMediaVisibility();
} }
handleProfileHover = e => {
if (!isMobile(window.innerWidth)) this.setState({ profileCardVisible: true });
}
handleProfileLeave = e => {
if (!isMobile(window.innerWidth)) this.setState({ profileCardVisible: false });
}
_properStatus() { _properStatus() {
const { status } = this.props; const { status } = this.props;
@ -437,6 +448,7 @@ class Status extends ImmutablePureComponent {
}; };
const statusUrl = `/@${status.getIn(['account', 'acct'])}/posts/${status.get('id')}`; const statusUrl = `/@${status.getIn(['account', 'acct'])}/posts/${status.get('id')}`;
const { profileCardVisible } = this.state;
return ( return (
<HotKeys handlers={handlers}> <HotKeys handlers={handlers}>
@ -450,13 +462,16 @@ class Status extends ImmutablePureComponent {
<RelativeTimestamp timestamp={status.get('created_at')} /> <RelativeTimestamp timestamp={status.get('created_at')} />
</NavLink> </NavLink>
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='status__display-name'> <div className='status__profile' onMouseEnter={this.handleProfileHover} onMouseLeave={this.handleProfileLeave}>
<div className='status__avatar'> <div className='status__avatar'>
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='floating-link' />
{statusAvatar} {statusAvatar}
</div> </div>
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='status__display-name'>
<DisplayName account={status.get('account')} others={otherAccounts} /> <DisplayName account={status.get('account')} others={otherAccounts} />
</NavLink> </NavLink>
<ProfileHoverCardContainer accountId={status.getIn(['account', 'id'])} visible={!isMobile(window.innerWidth) && profileCardVisible} />
</div>
</div> </div>
{!group && status.get('group') && ( {!group && status.get('group') && (

View file

@ -66,7 +66,6 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} }
}, },
onMuteNotifications(account, notifications) { onMuteNotifications(account, notifications) {
dispatch(muteAccount(account.get('id'), notifications)); dispatch(muteAccount(account.get('id'), notifications));
}, },

View file

@ -17,12 +17,9 @@ import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container';
import ProfileInfoPanel from '../../ui/components/profile_info_panel'; import ProfileInfoPanel from '../../ui/components/profile_info_panel';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import StillImage from 'soapbox/components/still_image'; import StillImage from 'soapbox/components/still_image';
import ActionButton from 'soapbox/features/ui/components/action_button';
const messages = defineMessages({ 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' }, edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
linkVerifiedOn: { id: 'account.link_verified_on', defaultMessage: 'Ownership of this link was checked on {date}' }, linkVerifiedOn: { id: 'account.link_verified_on', defaultMessage: 'Ownership of this link was checked on {date}' },
account_locked: { id: 'account.locked_info', defaultMessage: 'This account privacy status is set to locked. The owner manually reviews who can follow them.' }, account_locked: { id: 'account.locked_info', defaultMessage: 'This account privacy status is set to locked. The owner manually reviews who can follow them.' },
@ -65,8 +62,6 @@ class Header extends ImmutablePureComponent {
static propTypes = { static propTypes = {
account: ImmutablePropTypes.map, account: ImmutablePropTypes.map,
identity_props: ImmutablePropTypes.list, identity_props: ImmutablePropTypes.list,
onFollow: PropTypes.func.isRequired,
onBlock: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
username: PropTypes.string, username: PropTypes.string,
isStaff: PropTypes.bool.isRequired, isStaff: PropTypes.bool.isRequired,
@ -199,30 +194,6 @@ class Header extends ImmutablePureComponent {
return info; return info;
}; };
getActionBtn() {
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.props.onFollow} />;
} 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.props.onFollow} />;
} else if (account.getIn(['relationship', 'blocking'])) {
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />;
}
} else {
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.edit_profile)} to='/settings/profile' />;
}
return actionBtn;
};
render() { render() {
const { account, intl, username, me } = this.props; const { account, intl, username, me } = this.props;
const { isSmallScreen } = this.state; const { isSmallScreen } = this.state;
@ -247,7 +218,6 @@ class Header extends ImmutablePureComponent {
} }
const info = this.makeInfo(); const info = this.makeInfo();
const actionBtn = this.getActionBtn();
const menu = this.makeMenu(); const menu = this.makeMenu();
const headerMissing = (account.get('header').indexOf('/headers/original/missing.png') > -1); const headerMissing = (account.get('header').indexOf('/headers/original/missing.png') > -1);
@ -319,7 +289,7 @@ class Header extends ImmutablePureComponent {
{ {
me && me &&
<div className='account__header__extra__buttons'> <div className='account__header__extra__buttons'>
{actionBtn} <ActionButton account={account} />
{account.get('id') !== me && {account.get('id') !== me &&
<Button className='button button-alternative-2' onClick={this.props.onDirect}> <Button className='button button-alternative-2' onClick={this.props.onDirect}>
<FormattedMessage <FormattedMessage

View file

@ -0,0 +1,77 @@
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';
import classNames from 'classnames';
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,
}
getBadges = () => {
const { account } = this.props;
let badges = [];
if (isAdmin(account)) badges.push(<Badge key='admin' slug='admin' title='Admin' />);
if (isModerator(account)) badges.push(<Badge key='moderator' slug='moderator' title='Moderator' />);
if (account.getIn(['patron', 'is_patron'])) badges.push(<Badge key='patron' slug='patron' title='Patron' />);
return badges;
}
render() {
const { visible, accountId, account } = this.props;
if (!accountId) return null;
const accountBio = { __html: account.get('note_emojified') };
const followedBy = account.getIn(['relationship', 'followed_by']);
const badges = this.getBadges();
return (
<div className={classNames('profile-hover-card', { 'profile-hover-card--visible': visible })}>
<div className='profile-hover-card__container'>
{followedBy &&
<span className='relationship-tag'>
<FormattedMessage id='account.follows_you' defaultMessage='Follows you' />
</span>}
<div className='profile-hover-card__action-button'><ActionButton account={account} /></div>
<UserPanel className='profile-hover-card__user' accountId={accountId} />
{badges.length > 0 &&
<div className='profile-hover-card__badges'>
{badges}
</div>}
{account.getIn(['source', 'note'], '').length > 0 &&
<div className='profile-hover-card__bio' dangerouslySetInnerHTML={accountBio} />}
</div>
</div>
);
}
};

View file

@ -16,6 +16,8 @@ import classNames from 'classnames';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import PollContainer from 'soapbox/containers/poll_container'; import PollContainer from 'soapbox/containers/poll_container';
import { StatusInteractionBar } from './status_interaction_bar'; import { StatusInteractionBar } from './status_interaction_bar';
import ProfileHoverCardContainer from 'soapbox/features/profile_hover_card/profile_hover_card_container';
import { isMobile } from 'soapbox/is_mobile';
export default class DetailedStatus extends ImmutablePureComponent { export default class DetailedStatus extends ImmutablePureComponent {
@ -38,6 +40,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
state = { state = {
height: null, height: null,
profileCardVisible: false,
}; };
handleOpenVideo = (media, startTime) => { handleOpenVideo = (media, startTime) => {
@ -81,10 +84,19 @@ export default class DetailedStatus extends ImmutablePureComponent {
window.open(href, 'soapbox-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes'); window.open(href, 'soapbox-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
} }
handleProfileHover = e => {
if (!isMobile(window.innerWidth)) this.setState({ profileCardVisible: true });
}
handleProfileLeave = e => {
if (!isMobile(window.innerWidth)) this.setState({ profileCardVisible: false });
}
render() { render() {
const status = (this.props.status && this.props.status.get('reblog')) ? this.props.status.get('reblog') : this.props.status; const status = (this.props.status && this.props.status.get('reblog')) ? this.props.status.get('reblog') : this.props.status;
const outerStyle = { boxSizing: 'border-box' }; const outerStyle = { boxSizing: 'border-box' };
const { compact } = this.props; const { compact } = this.props;
const { profileCardVisible } = this.state;
if (!status) { if (!status) {
return null; return null;
@ -160,10 +172,19 @@ export default class DetailedStatus extends ImmutablePureComponent {
return ( return (
<div style={outerStyle}> <div style={outerStyle}>
<div ref={this.setRef} className={classNames('detailed-status', { compact })}> <div ref={this.setRef} className={classNames('detailed-status', { compact })}>
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} className='detailed-status__display-name'> <div className='detailed-status__profile' onMouseEnter={this.handleProfileHover} onMouseLeave={this.handleProfileLeave}>
<div className='detailed-status__display-avatar'><Avatar account={status.get('account')} size={48} /></div> <div className='detailed-status__display-name'>
<DisplayName account={status.get('account')} /> <NavLink to={`/@${status.getIn(['account', 'acct'])}`}>
</NavLink> <div className='detailed-status__display-avatar'>
<Avatar account={status.get('account')} size={48} />
</div>
</NavLink>
<DisplayName account={status.get('account')}>
<NavLink to={`/@${status.getIn(['account', 'acct'])}`} title={status.getIn(['account', 'acct'])} className='floating-link' />
</DisplayName>
</div>
<ProfileHoverCardContainer accountId={status.getIn(['account', 'id'])} visible={!isMobile(window.innerWidth) && profileCardVisible} />
</div>
{status.get('group') && ( {status.get('group') && (
<div className='status__meta'> <div className='status__meta'>

View file

@ -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;
}
}

View file

@ -84,17 +84,17 @@ class UserPanel extends ImmutablePureComponent {
}; };
const makeMapStateToProps = () => {
const mapStateToProps = state => {
const me = state.get('me');
const getAccount = makeGetAccount(); const getAccount = makeGetAccount();
return { const mapStateToProps = (state, { accountId }) => ({
account: getAccount(state, me), account: getAccount(state, accountId),
}; });
return mapStateToProps;
}; };
export default injectIntl( export default injectIntl(
connect(mapStateToProps, null, null, { connect(makeMapStateToProps, null, null, {
forwardRef: true, forwardRef: true,
})(UserPanel)); })(UserPanel));

View file

@ -15,6 +15,7 @@ import { getFeatures } from 'soapbox/utils/features';
const mapStateToProps = state => { const mapStateToProps = state => {
const me = state.get('me'); const me = state.get('me');
return { return {
me,
account: state.getIn(['accounts', me]), account: state.getIn(['accounts', me]),
hasPatron: state.getIn(['soapbox', 'extensions', 'patron', 'enabled']), hasPatron: state.getIn(['soapbox', 'extensions', 'patron', 'enabled']),
features: getFeatures(state.get('instance')), features: getFeatures(state.get('instance')),
@ -30,7 +31,7 @@ class HomePage extends ImmutablePureComponent {
} }
render() { render() {
const { children, account, hasPatron, features } = this.props; const { me, children, account, hasPatron, features } = this.props;
return ( return (
<div className='page'> <div className='page'>
@ -39,7 +40,7 @@ class HomePage extends ImmutablePureComponent {
<div className='columns-area__panels__pane columns-area__panels__pane--left'> <div className='columns-area__panels__pane columns-area__panels__pane--left'>
<div className='columns-area__panels__pane__inner'> <div className='columns-area__panels__pane__inner'>
<UserPanel /> <UserPanel accountId={me} />
{hasPatron && <FundingPanel />} {hasPatron && <FundingPanel />}
<PromoPanel /> <PromoPanel />
<LinkFooter /> <LinkFooter />

View file

@ -71,3 +71,4 @@
@import 'components/error-boundary'; @import 'components/error-boundary';
@import 'components/video-player'; @import 'components/video-player';
@import 'components/audio-player'; @import 'components/audio-player';
@import 'components/profile_hover_card';

View file

@ -218,3 +218,14 @@ noscript {
} }
} }
} }
.floating-link {
width: 100%;
height: 100%;
top: 0;
right: 0;
bottom: 0;
left: 0;
position: absolute;
z-index: 9999;
}

View file

@ -41,6 +41,7 @@ a.account__display-name {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
position: relative;
} }
.display-name__html { .display-name__html {

View file

@ -20,7 +20,7 @@
.column, .column,
.drawer { .drawer {
flex: 1 1 100%; flex: 1 1 100%;
overflow: hidden; overflow: visible;
} }
.drawer__pager { .drawer__pager {

View file

@ -0,0 +1,96 @@
.display-name__account {
position: relative;
cursor: pointer;
}
.display-name .profile-hover-card {
white-space: normal;
}
.profile-hover-card {
position: absolute;
pointer-events: none;
opacity: 0;
transition-property: opacity;
transition-duration: 0.2s;
transition-delay: 0.7s;
width: 300px;
z-index: 998;
left: -10px;
padding-top: 20px;
margin-bottom: 10px;
&--visible {
opacity: 1;
pointer-events: all;
}
@media(min-width: 750px) {
left: -80px;
}
.profile-hover-card__container {
@include standard-panel;
position: relative;
overflow: hidden;
}
.profile-hover-card__action-button {
z-index: 999;
position: absolute;
right: 20px;
top: 120px;
}
.user-panel {
box-shadow: none;
width: auto;
.user-panel-stats-item a strong {
text-decoration: none;
}
}
.relationship-tag {
position: absolute;
top: 10px;
left: 10px;
z-index: 1;
}
.profile-hover-card__badges {
margin: 0 20px 20px;
display: flex;
.badge {
padding: 2px 4px;
margin-right: 5px;
border-radius: 3px;
font-size: 11px;
opacity: 1;
}
}
.profile-hover-card__bio {
margin: 0 20px 20px;
max-height: 4em;
&::after {
content: '';
display: block;
position: absolute;
width: 100%;
height: 20px;
bottom: 0;
left: 0;
background: linear-gradient(0deg, var(--foreground-color) 0%, var(--foreground-color), 80%, transparent);
}
}
}
.detailed-status {
.profile-hover-card {
top: 0;
left: 80px;
}
}

View file

@ -210,7 +210,6 @@
.status__info .status__display-name { .status__info .status__display-name {
display: block; display: block;
max-width: 100%; max-width: 100%;
padding-right: 25px;
} }
.status__info { .status__info {
@ -218,6 +217,11 @@
z-index: 4; z-index: 4;
} }
.status__profile,
.detailed-status__profile {
display: inline-block;
}
.status-check-box { .status-check-box {
border-bottom: 1px solid var(--background-color); border-bottom: 1px solid var(--background-color);
display: flex; display: flex;

View file

@ -3,7 +3,13 @@
display: flex; display: flex;
width: 265px; width: 265px;
flex-direction: column; flex-direction: column;
overflow-y: hidden;
&,
.user-panel__account__name,
.user-panel__account__username {
overflow: hidden;
text-overflow: ellipsis;
}
&__header { &__header {
display: block; display: block;