Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite AvatarOverlay component with React hooks #24543

Merged
merged 3 commits into from
Apr 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rewrite AvatarOverlay component with React hooks
  • Loading branch information
takayamaki committed Apr 16, 2023
commit 9355c4c5c8649ac6f2527faa187e2e75c6e22ca8
75 changes: 25 additions & 50 deletions app/javascript/mastodon/components/avatar_overlay.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { autoPlayGif } from '../initial_state';
import Avatar from './avatar';

export default class AvatarOverlay extends React.PureComponent {

static propTypes = {
account: ImmutablePropTypes.map.isRequired,
friend: ImmutablePropTypes.map.isRequired,
animate: PropTypes.bool,
size: PropTypes.number,
baseSize: PropTypes.number,
overlaySize: PropTypes.number,
};

static defaultProps = {
animate: autoPlayGif,
size: 46,
baseSize: 36,
overlaySize: 24,
};

state = {
hovering: false,
};

handleMouseEnter = () => {
if (this.props.animate) return;
this.setState({ hovering: true });
};

handleMouseLeave = () => {
if (this.props.animate) return;
this.setState({ hovering: false });
};

render() {
const { account, friend, animate, size, baseSize, overlaySize } = this.props;
const { hovering } = this.state;

return (
<div className='account__avatar-overlay' style={{ width: size, height: size }}>
<div className='account__avatar-overlay-base'><Avatar animate={hovering || animate} account={account} size={baseSize} /></div>
<div className='account__avatar-overlay-overlay'><Avatar animate={hovering || animate} account={friend} size={overlaySize} /></div>
</div>
);
}

}
import type { Account } from '../../types/resources';
import { Avatar } from './avatar';

type Props = {
account: Account;
friend: Account;
size?: number;
baseSize?: number;
overlaySize?: number;
};

export const AvatarOverlay: React.FC<Props> = ({
account,
friend,
size = 46,
baseSize = 36,
overlaySize = 24,
}) => (
<div className='account__avatar-overlay' style={{ width: size, height: size }}>
<div className='account__avatar-overlay-base'><Avatar account={account} size={baseSize} /></div>
<div className='account__avatar-overlay-overlay'><Avatar account={friend} size={overlaySize} /></div>
</div>
);

export default AvatarOverlay;