Skip to content

Commit 23abe41

Browse files
authored
Feature: Image optimizations and minor fixes (#252)
Description: * Changed images to use Angular's optimized image directive * Bold fonts now have the correct font weight Future issues: Optimized images for other pages might act funny due to hydration.
1 parent 08e42de commit 23abe41

18 files changed

Lines changed: 80 additions & 50 deletions
22.5 KB
Binary file not shown.
File renamed without changes.

public/fonts/inter-latin-700.woff2

23.8 KB
Binary file not shown.
18.4 KB
Binary file not shown.
File renamed without changes.

public/images/mural.jpg

414 KB
Loading

src/app/pages/officers/officers.component.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ <h1>Officers</h1>
1616
<section>
1717
<h2>Our Executives</h2>
1818
<div class="gallery">
19-
@for (exec of currentAdministration()?.members; track $index) {
20-
<div class="card">
19+
@for (exec of currentAdministration()?.members; track exec.photoName; let i = $index) {
20+
<div class="card" [style.visibility]="areImagesLoaded() ? 'visible' : 'hidden'">
2121
<div class="card__frame">
22-
<img class="card__img" [src]="exec.photoName" [alt]="exec.photoName" />
22+
<img
23+
class="card__img"
24+
[ngSrc]="exec.photoName"
25+
width="300"
26+
height="400"
27+
[alt]="exec.photoName"
28+
[priority]="i < PRIORITY"
29+
(load)="onLoad(i)"
30+
/>
2331
<div class="card__info">
2432
<div class="card__name">
2533
<strong class="card__text">{{ exec.name }}</strong>

src/app/pages/officers/officers.component.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
justify-content: center;
1313

1414
&__frame {
15-
width: max(300px, 100%);
15+
width: max(18.75rem, 100%);
1616
position: relative;
1717
}
1818

1919
&__img {
20-
width: 300px;
20+
width: 18.75rem;
2121
aspect-ratio: 3 / 4;
2222
box-shadow: 10px 10px 5px black;
2323
}

src/app/pages/officers/officers.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NgOptimizedImage } from '@angular/common';
12
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
23
import { CodeArticleComponent } from '@csss-code/article/article.component';
34
import { ExternalLinkComponent } from 'components/url/external-link/external-link.component';
@@ -6,12 +7,13 @@ import { ExecutiveAdministration, executives } from './officers.data';
67

78
@Component({
89
selector: 'cs-officers',
9-
imports: [CodeArticleComponent, RouteLinkComponent, ExternalLinkComponent],
10+
imports: [CodeArticleComponent, RouteLinkComponent, ExternalLinkComponent, NgOptimizedImage],
1011
templateUrl: './officers.component.html',
1112
styleUrl: './officers.component.scss',
1213
changeDetection: ChangeDetectionStrategy.OnPush
1314
})
1415
export class OfficersComponent {
16+
protected PRIORITY = 10;
1517
/**
1618
* The year currently selected.
1719
*/
@@ -46,4 +48,16 @@ export class OfficersComponent {
4648
* Will probably need some way to remove older cached entries if memory becomes an issue.
4749
*/
4850
private cachedAdmins = new Map<number, ExecutiveAdministration>();
51+
52+
private loadedImages = signal(new Set<number>());
53+
54+
areImagesLoaded = computed(
55+
() =>
56+
this.loadedImages().size >= (this.currentAdministration()?.members ?? []).length ||
57+
this.loadedImages().size >= this.PRIORITY
58+
);
59+
60+
onLoad(id: number): void {
61+
this.loadedImages.update(ids => new Set([...ids, id]));
62+
}
4963
}

0 commit comments

Comments
 (0)