Skip to content

Commit 36f9568

Browse files
authored
feat: remove unnecessary computation from al-avatar (#252)
1 parent 5c9374d commit 36f9568

File tree

7 files changed

+12
-34
lines changed

7 files changed

+12
-34
lines changed

libs/blog/articles/ui-article-card/src/lib/components/article-compact-card/article-compact-card.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<div class="flex items-center justify-between px-6 pt-6">
1919
<div class="flex items-center gap-2 max-md:self-start">
20-
<al-avatar [imageSrc]="article().author.avatarUrl" size="sm" />
20+
<al-avatar [imageSrc]="article().author.avatarUrl" size="32" />
2121
<span class="text-sm/[14px] font-medium">
2222
{{ article().author.name }}
2323
</span>

libs/blog/articles/ui-article-card/src/lib/components/article-hero-card/article-hero-card.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<div class="flex items-center justify-between px-8 pt-8">
1818
<div class="flex items-center gap-2 max-md:self-start">
19-
<al-avatar [imageSrc]="article().author.avatarUrl" size="sm" />
19+
<al-avatar [imageSrc]="article().author.avatarUrl" size="32" />
2020
<span class="text-sm/[14px] font-medium">
2121
{{ article().author.name }}
2222
</span>

libs/blog/articles/ui-article-card/src/lib/components/article-horizontal-card/article-horizontal-card.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<al-avatar
1818
[imageSrc]="article().author.avatarUrl"
1919
[priority]="imagePriority()"
20-
size="sm"
20+
size="32"
2121
/>
2222
<span class="text-sm/[14px] font-medium">
2323
{{ article().author.name }}

libs/blog/articles/ui-article-card/src/lib/components/article-regular-card/article-regular-card.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<al-avatar
2222
[imageSrc]="article().author.avatarUrl"
2323
[priority]="imagePriority()"
24-
size="sm"
24+
size="32"
2525
/>
2626
<span class="text-sm/[14px] font-medium">
2727
{{ article().author.name }}

libs/blog/authors/ui-author-card/src/lib/author-card/author-card.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<ng-template #avatar>
3636
<div class="flex flex-col items-center gap-4">
37-
<al-avatar [imageSrc]="author().avatarUrl" size="md" />
37+
<al-avatar [imageSrc]="author().avatarUrl" size="96" />
3838
<span
3939
class="line-clamp-2 font-bold leading-none"
4040
[id]="'author-title-' + author().slug"
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
<div
22
class="flex items-center justify-center overflow-hidden rounded-full border border-white bg-gray-200"
3-
[ngStyle]="{
4-
height: sideLength() + 'px',
5-
width: sideLength() + 'px',
6-
}"
73
>
84
@if (imageSrc()) {
95
<img
106
alt=""
117
[ngSrc]="imageSrc()"
12-
[width]="sideLength()"
13-
[height]="sideLength()"
8+
[width]="size()"
9+
[height]="size()"
1410
[priority]="priority()"
1511
/>
1612
} @else {
17-
<ng-icon name="heroUsers"></ng-icon>
13+
<div></div>
1814
}
1915
</div>
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import { NgOptimizedImage, NgStyle } from '@angular/common';
2-
import {
3-
ChangeDetectionStrategy,
4-
Component,
5-
computed,
6-
input,
7-
} from '@angular/core';
8-
import { NgIconComponent, provideIcons } from '@ng-icons/core';
9-
import { heroUsers } from '@ng-icons/heroicons/outline';
2+
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
3+
import { NgIconComponent } from '@ng-icons/core';
104

11-
type AvatarSize = 'sm' | 'md';
5+
type AvatarSize = '32' | '96';
126

137
@Component({
148
standalone: true,
@@ -17,21 +11,9 @@ type AvatarSize = 'sm' | 'md';
1711
styleUrls: ['./avatar.component.scss'],
1812
changeDetection: ChangeDetectionStrategy.OnPush,
1913
imports: [NgOptimizedImage, NgIconComponent, NgStyle],
20-
providers: [provideIcons({ heroUsers })],
2114
})
2215
export class AvatarComponent {
2316
readonly imageSrc = input.required<string>();
24-
readonly size = input<AvatarSize>('sm');
17+
readonly size = input<AvatarSize>('32');
2518
readonly priority = input<number | null>(null);
26-
27-
protected sideLength = computed(() => {
28-
switch (this.size()) {
29-
case 'sm':
30-
return '32';
31-
case 'md':
32-
return '96';
33-
default:
34-
return '32';
35-
}
36-
});
3719
}

0 commit comments

Comments
 (0)