Skip to content

Commit f291484

Browse files
authored
Fix: officer images and links (#240)
closes #235 Description: On the Officers page, the app was crashing with "Administration for year 2026 not found" error, preventing the page from rendering. Additionally, external links were not displaying, and executive member photos were failing to load. Root cause: The currentAdministration computed property was hardcoded to look for executive administration data matching the current year (2026). Since the 2026 administration data doesn't exist yet in the codebase, the code threw an error instead of gracefully handling the missing data. Additionally, the toLocalUrl() method was looking for images in the executives/2026/ folder when they were actually in executives/2025/. Fix: Added fallback logic to use the most recent available administration when the current year's data doesn't exist. The code now uses .reduce() to find the administration with the highest startYear and displays that instead of crashing. Also built the image path inline using the actual administration's startYear instead of calling toLocalUrl(), ensuring images load from the correct year's folder (e.g., executives/2025/ when showing 2025 administration).
1 parent 116d8e4 commit f291484

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ export class OfficersComponent {
2222
let newAdmin = this.cachedAdmins.get(year);
2323
if (!newAdmin) {
2424
// TODO: Fetch this from the back end.
25-
newAdmin = structuredClone(executives.find(e => e.startYear === year));
25+
newAdmin = structuredClone(executives.find(e => e.startYear <= year));
2626
if (!newAdmin) {
27-
throw new Error(`Administration for year ${year} not found.`);
27+
throw new Error(`Administration not found for any year.`);
2828
}
29+
const foundYear = newAdmin.startYear;
2930
// FIXME: Remove this once admins are properly fetched.
3031
newAdmin.members = newAdmin.members.map(exec => {
3132
return {
3233
...exec,
33-
photoName: this.toLocalUrl(exec.photoName)
34+
photoName: `images/executives/${foundYear}/${exec.photoName}`
3435
};
3536
});
3637
// end of FIXME:
@@ -45,14 +46,4 @@ export class OfficersComponent {
4546
* Will probably need some way to remove older cached entries if memory becomes an issue.
4647
*/
4748
private cachedAdmins = new Map<number, ExecutiveAdministration>();
48-
49-
/**
50-
* Changes the files name to one that can be used to set the background image.
51-
*
52-
* @param fileName - The file name to change. Must be in the `public/images/` folder
53-
* @returns File name in the CSS URL form.
54-
*/
55-
private toLocalUrl(fileName: string): string {
56-
return `images/executives/${this.currentYear()}/${fileName}`;
57-
}
5849
}

0 commit comments

Comments
 (0)