From 7e09c9d80df1f94ed88ed6edd58804b2ff9d578c Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 06:04:28 +0000 Subject: [PATCH] fix: load the profile once per switch and show an error for unknown users --- .../components/profile-articles.component.ts | 29 +++++-------------- .../components/profile-favorites.component.ts | 29 +++++-------------- .../pages/profile/profile.component.ts | 6 +++- 3 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/app/features/profile/components/profile-articles.component.ts b/src/app/features/profile/components/profile-articles.component.ts index 088b6b572..3ae91fc19 100644 --- a/src/app/features/profile/components/profile-articles.component.ts +++ b/src/app/features/profile/components/profile-articles.component.ts @@ -1,11 +1,8 @@ import { ChangeDetectionStrategy, Component, DestroyRef, inject, OnInit, signal } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { ArticleListComponent } from '../../article/components/article-list.component'; -import { ProfileService } from '../services/profile.service'; -import { Profile } from '../models/profile.model'; import { ArticleListConfig } from '../../article/models/article-list-config.model'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { switchMap } from 'rxjs/operators'; @Component({ selector: 'app-profile-articles', @@ -16,31 +13,19 @@ import { switchMap } from 'rxjs/operators'; changeDetection: ChangeDetectionStrategy.OnPush, }) export default class ProfileArticlesComponent implements OnInit { - profile = signal(null); articlesConfig = signal(null); destroyRef = inject(DestroyRef); - constructor( - private route: ActivatedRoute, - private readonly profileService: ProfileService, - ) {} + constructor(private route: ActivatedRoute) {} ngOnInit(): void { - this.route.paramMap - .pipe( - switchMap(params => this.profileService.get(params.get('username')!)), - takeUntilDestroyed(this.destroyRef), - ) - .subscribe({ - next: (profile: Profile) => { - this.profile.set(profile); - this.articlesConfig.set({ - type: 'all', - filters: { - author: profile.username, - }, - }); + this.route.parent!.paramMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => { + this.articlesConfig.set({ + type: 'all', + filters: { + author: params.get('username')!, }, }); + }); } } diff --git a/src/app/features/profile/components/profile-favorites.component.ts b/src/app/features/profile/components/profile-favorites.component.ts index 0f8565663..50dead924 100644 --- a/src/app/features/profile/components/profile-favorites.component.ts +++ b/src/app/features/profile/components/profile-favorites.component.ts @@ -1,11 +1,8 @@ import { ChangeDetectionStrategy, Component, DestroyRef, inject, OnInit, signal } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { ArticleListComponent } from '../../article/components/article-list.component'; -import { ProfileService } from '../services/profile.service'; -import { Profile } from '../models/profile.model'; import { ArticleListConfig } from '../../article/models/article-list-config.model'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { switchMap } from 'rxjs/operators'; @Component({ selector: 'app-profile-favorites', @@ -16,31 +13,19 @@ import { switchMap } from 'rxjs/operators'; changeDetection: ChangeDetectionStrategy.OnPush, }) export default class ProfileFavoritesComponent implements OnInit { - profile = signal(null); favoritesConfig = signal(null); destroyRef = inject(DestroyRef); - constructor( - private route: ActivatedRoute, - private readonly profileService: ProfileService, - ) {} + constructor(private route: ActivatedRoute) {} ngOnInit() { - this.route - .parent!.paramMap.pipe( - switchMap(params => this.profileService.get(params.get('username')!)), - takeUntilDestroyed(this.destroyRef), - ) - .subscribe({ - next: (profile: Profile) => { - this.profile.set(profile); - this.favoritesConfig.set({ - type: 'all', - filters: { - favorited: profile.username, - }, - }); + this.route.parent!.paramMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => { + this.favoritesConfig.set({ + type: 'all', + filters: { + favorited: params.get('username')!, }, }); + }); } } diff --git a/src/app/features/profile/pages/profile/profile.component.ts b/src/app/features/profile/pages/profile/profile.component.ts index 79a8b7443..58ce87c2f 100644 --- a/src/app/features/profile/pages/profile/profile.component.ts +++ b/src/app/features/profile/pages/profile/profile.component.ts @@ -46,7 +46,11 @@ export class ProfileComponent implements OnInit { this.errors.set(null); return this.profileService.get(params.get('username')!).pipe( catchError(error => { - this.errors.set(error.errors || { error: ['Failed to load profile'] }); + this.errors.set( + error.status === 404 + ? { errors: { profile: ['not found'] } } + : { errors: error.errors ?? { profile: ['could not be loaded'] } }, + ); return EMPTY; }), );