Skip to content

Commit

Permalink
[Glitch] Update Avatar, AvatarComposite, and AvatarOverlay comp…
Browse files Browse the repository at this point in the history
…onents

Various ports including 8dfe517,
d1de7fb and
9f8d346.

Co-Authored-By: Eugen Rochko <[email protected]>
Co-Authored-By: fusagiko / takayamaki <[email protected]>
  • Loading branch information
3 people committed Dec 9, 2023
1 parent c0e5629 commit 711184f
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 94 deletions.
33 changes: 14 additions & 19 deletions app/javascript/flavours/glitch/components/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,44 @@ import { autoPlayGif } from '../initial_state';
import type { Account } from '../types/resources';

interface Props {
account: Account | undefined;
className?: string;
account: Account | undefined; // FIXME: remove `undefined` once we know for sure its always there
size: number;
style?: React.CSSProperties;
inline?: boolean;
animate?: boolean;
}

export const Avatar: React.FC<Props> = ({
account,
className,
animate = autoPlayGif,
size = 20,
inline = false,
style: styleFromParent,
}) => {
const { hovering, handleMouseEnter, handleMouseLeave } =
useHovering(autoPlayGif);
const { hovering, handleMouseEnter, handleMouseLeave } = useHovering(animate);

const style = {
...styleFromParent,
width: `${size}px`,
height: `${size}px`,
backgroundSize: `${size}px ${size}px`,
};

if (account) {
style.backgroundImage = `url(${account.get(
hovering ? 'avatar' : 'avatar_static',
)})`;
}
const src =
hovering || animate
? account?.get('avatar')
: account?.get('avatar_static');

return (
<div
className={classNames(
'account__avatar',
{ 'account__avatar-inline': inline },
className,
)}
className={classNames('account__avatar', {
'account__avatar-inline': inline,
})}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
style={style}
data-avatar-of={account && `@${account.get('acct')}`}
role='img'
aria-label={account?.get('acct')}
/>
>
{src && <img src={src} alt={account?.get('acct')} />}
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ImmutablePropTypes from 'react-immutable-proptypes';

import { autoPlayGif } from '../initial_state';

import { Avatar } from './avatar';

export default class AvatarComposite extends PureComponent {

static propTypes = {
Expand Down Expand Up @@ -76,12 +78,12 @@ export default class AvatarComposite extends PureComponent {
bottom: bottom,
width: `${width}%`,
height: `${height}%`,
backgroundSize: 'cover',
backgroundImage: `url(${account.get(animate ? 'avatar' : 'avatar_static')})`,
};

return (
<div key={account.get('id')} style={style} data-avatar-of={`@${account.get('acct')}`} />
<div key={account.get('id')} style={style}>
<Avatar account={account} animate={animate} />
</div>
);
}

Expand Down
39 changes: 0 additions & 39 deletions app/javascript/flavours/glitch/components/avatar_overlay.jsx

This file was deleted.

56 changes: 56 additions & 0 deletions app/javascript/flavours/glitch/components/avatar_overlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useHovering } from '../hooks/useHovering';
import { autoPlayGif } from '../initial_state';
import type { Account } from '../types/resources';

interface Props {
account: Account | undefined; // FIXME: remove `undefined` once we know for sure its always there
friend: Account | undefined; // FIXME: remove `undefined` once we know for sure its always there
size?: number;
baseSize?: number;
overlaySize?: number;
}

export const AvatarOverlay: React.FC<Props> = ({
account,
friend,
size = 46,
baseSize = 36,
overlaySize = 24,
}) => {
const { hovering, handleMouseEnter, handleMouseLeave } =
useHovering(autoPlayGif);
const accountSrc = hovering
? account?.get('avatar')
: account?.get('avatar_static');
const friendSrc = hovering
? friend?.get('avatar')
: friend?.get('avatar_static');

return (
<div
className='account__avatar-overlay'
style={{ width: size, height: size }}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div className='account__avatar-overlay-base'>
<div
className='account__avatar'
style={{ width: `${baseSize}px`, height: `${baseSize}px` }}
data-avatar-of={`@${account.get('acct')}`}

Check failure on line 40 in app/javascript/flavours/glitch/components/avatar_overlay.tsx

View workflow job for this annotation

GitHub Actions / lint

'account' is possibly 'undefined'.
>
{accountSrc && <img src={accountSrc} alt={account?.get('acct')} />}
</div>
</div>
<div className='account__avatar-overlay-overlay'>
<div
className='account__avatar'
style={{ width: `${overlaySize}px`, height: `${overlaySize}px` }}
data-avatar-of={`@${friend.get('acct')}`}

Check failure on line 49 in app/javascript/flavours/glitch/components/avatar_overlay.tsx

View workflow job for this annotation

GitHub Actions / lint

'friend' is possibly 'undefined'.
>
{friendSrc && <img src={friendSrc} alt={friend?.get('acct')} />}
</div>
</div>
</div>
);
};
4 changes: 2 additions & 2 deletions app/javascript/flavours/glitch/components/status_header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes';

// Mastodon imports.
import { Avatar } from './avatar';
import AvatarOverlay from './avatar_overlay';
import { AvatarOverlay } from './avatar_overlay';
import { DisplayName } from './display_name';

export default class StatusHeader extends PureComponent {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default class StatusHeader extends PureComponent {

let statusAvatar;
if (friend === undefined || friend === null) {
statusAvatar = <Avatar account={account} size={48} />;
statusAvatar = <Avatar account={account} size={46} />;
} else {
statusAvatar = <AvatarOverlay account={account} friend={friend} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import { Icon } from 'flavours/glitch/components/icon';
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';

import AvatarOverlay from '../../../components/avatar_overlay';
import { AvatarOverlay } from '../../../components/avatar_overlay';
import { DisplayName } from '../../../components/display_name';

class MovedNote extends ImmutablePureComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';

import AvatarOverlay from 'flavours/glitch/components/avatar_overlay';
import { AvatarOverlay } from 'flavours/glitch/components/avatar_overlay';
import { RelativeTimestamp } from 'flavours/glitch/components/relative_timestamp';

// This needs to be kept in sync with app/models/report.rb
Expand Down
43 changes: 14 additions & 29 deletions app/javascript/flavours/glitch/styles/components/accounts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@

display: block;
position: relative;
cursor: pointer;
width: 36px;
height: 36px;
background-size: 36px 36px;
overflow: hidden;

img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}

&-inline {
display: inline-block;
Expand All @@ -102,14 +106,19 @@
overflow: hidden;
position: relative;

& div {
& > div {
@include avatar-radius;

float: left;
position: relative;
box-sizing: border-box;
}

.account__avatar {
width: 100% !important;
height: 100% !important;
}

&__label {
display: block;
position: absolute;
Expand All @@ -125,37 +134,13 @@
}

.account__avatar-overlay {
@include avatar-size(48px);

position: relative;

&-base {
@include avatar-radius;
@include avatar-size(36px);

img {
@include avatar-radius;

width: 100%;
height: 100%;
}
}

&-overlay {
@include avatar-radius;
@include avatar-size(24px);

position: absolute;
bottom: 0;
inset-inline-end: 0;
z-index: 1;

img {
@include avatar-radius;

width: 100%;
height: 100%;
}
}
}

Expand Down

0 comments on commit 711184f

Please sign in to comment.