Skip to content

Commit

Permalink
Change the filtered notification count to be in the account avatar (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap authored Aug 2, 2024
1 parent 99c446b commit cc453f2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
12 changes: 12 additions & 0 deletions app/javascript/mastodon/components/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface Props {
style?: React.CSSProperties;
inline?: boolean;
animate?: boolean;
counter?: number | string;
counterBorderColor?: string;
}

export const Avatar: React.FC<Props> = ({
Expand All @@ -19,6 +21,8 @@ export const Avatar: React.FC<Props> = ({
size = 20,
inline = false,
style: styleFromParent,
counter,
counterBorderColor,
}) => {
const { hovering, handleMouseEnter, handleMouseLeave } = useHovering(animate);

Expand All @@ -43,6 +47,14 @@ export const Avatar: React.FC<Props> = ({
style={style}
>
{src && <img src={src} alt='' />}
{counter && (
<div
className='account__avatar__counter'
style={{ borderColor: counterBorderColor }}
>
{counter}
</div>
)}
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ export const NotificationRequest = ({ id, accountId, notificationsCount }) => {
return (
<div className='notification-request'>
<Link to={`/notifications/requests/${id}`} className='notification-request__link'>
<Avatar account={account} size={36} />
<Avatar account={account} size={40} counter={toCappedNumber(notificationsCount)} />

<div className='notification-request__name'>
<div className='notification-request__name__display-name'>
<bdi><strong dangerouslySetInnerHTML={{ __html: account?.get('display_name_html') }} /></bdi>
<span className='filtered-notifications-banner__badge'>{toCappedNumber(notificationsCount)}</span>
</div>

<span>@{account?.get('acct')}</span>
Expand Down
13 changes: 0 additions & 13 deletions app/javascript/styles/mastodon/_mixins.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
@mixin avatar-radius {
border-radius: 4px;
background: transparent no-repeat;
background-position: 50%;
background-clip: padding-box;
}

@mixin avatar-size($size: 48px) {
width: $size;
height: $size;
background-size: $size $size;
}

@mixin search-input {
outline: 0;
box-sizing: border-box;
Expand Down
27 changes: 24 additions & 3 deletions app/javascript/styles/mastodon/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1980,17 +1980,15 @@ body > [data-popper-placement] {
}

.account__avatar {
@include avatar-radius;

display: block;
position: relative;
overflow: hidden;

img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 4px;
}

&-inline {
Expand Down Expand Up @@ -2027,6 +2025,29 @@ body > [data-popper-placement] {
font-size: 15px;
}
}

&__counter {
$height: 16px;
$h-padding: 5px;

position: absolute;
bottom: -3px;
inset-inline-end: -3px;
padding-left: $h-padding;
padding-right: $h-padding;
height: $height;
border-radius: $height;
min-width: $height - 2 * $h-padding; // to ensure that it is never narrower than a circle
line-height: $height + 1px; // to visually center the numbers
background-color: $ui-button-background-color;
color: $white;
border-width: 1px;
border-style: solid;
border-color: var(--background-color);
font-size: 11px;
font-weight: 500;
text-align: center;
}
}

a .account__avatar {
Expand Down

0 comments on commit cc453f2

Please sign in to comment.