From 6c61a394b88fc4979b85fcea538cf2f15a07936b Mon Sep 17 00:00:00 2001 From: nsemets Date: Fri, 12 Dec 2025 11:38:24 +0200 Subject: [PATCH 1/3] fix(profile): added prerender for user profile --- src/app/features/profile/profile.component.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app/features/profile/profile.component.ts b/src/app/features/profile/profile.component.ts index ee2b9b23e..f17eaccf5 100644 --- a/src/app/features/profile/profile.component.ts +++ b/src/app/features/profile/profile.component.ts @@ -4,13 +4,14 @@ import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, OnIni import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ActivatedRoute, Router } from '@angular/router'; +import { PrerenderReadyService } from '@core/services/prerender-ready.service'; import { UserSelectors } from '@core/store/user'; import { GlobalSearchComponent } from '@osf/shared/components/global-search/global-search.component'; import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component'; import { SEARCH_TAB_OPTIONS } from '@osf/shared/constants/search-tab-options.const'; import { ResourceType } from '@osf/shared/enums/resource-type.enum'; +import { UserModel } from '@osf/shared/models/user/user.models'; import { SetDefaultFilterValue } from '@osf/shared/stores/global-search'; -import { UserModel } from '@shared/models/user/user.models'; import { ProfileInformationComponent } from './components'; import { FetchUserProfile, ProfileSelectors, SetUserProfile } from './store'; @@ -26,16 +27,18 @@ export class ProfileComponent implements OnInit { private router = inject(Router); private route = inject(ActivatedRoute); private destroyRef = inject(DestroyRef); + private readonly prerenderReady = inject(PrerenderReadyService); + private actions = createDispatchMap({ fetchUserProfile: FetchUserProfile, setDefaultFilterValue: SetDefaultFilterValue, setUserProfile: SetUserProfile, }); - private loggedInUser = select(UserSelectors.getCurrentUser); - private userProfile = select(ProfileSelectors.getUserProfile); - + loggedInUser = select(UserSelectors.getCurrentUser); + userProfile = select(ProfileSelectors.getUserProfile); isUserLoading = select(ProfileSelectors.isUserProfileLoading); + resourceTabOptions = SEARCH_TAB_OPTIONS.filter((x) => x.value !== ResourceType.Agent); isMyProfile = computed(() => !this.route.snapshot.params['id']); @@ -66,17 +69,23 @@ export class ProfileComponent implements OnInit { private setupMyProfile(user: UserModel): void { this.actions.setUserProfile(user); + if (user?.iri) { this.actions.setDefaultFilterValue('creator,isContainedBy.creator', user.iri); this.defaultSearchFiltersInitialized.set(true); } + + this.prerenderReady.setReady(); } private setSearchFilter(): void { const currentUser = this.user(); + if (currentUser?.iri) { this.actions.setDefaultFilterValue('creator,isContainedBy.creator', currentUser.iri); this.defaultSearchFiltersInitialized.set(true); } + + this.prerenderReady.setReady(); } } From 342c564308d9bcfc0ccbba4ac45267a3947722bd Mon Sep 17 00:00:00 2001 From: nsemets Date: Fri, 12 Dec 2025 11:42:46 +0200 Subject: [PATCH 2/3] fix(profile): set not ready when component destroys --- src/app/features/profile/profile.component.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app/features/profile/profile.component.ts b/src/app/features/profile/profile.component.ts index f17eaccf5..9aac4d808 100644 --- a/src/app/features/profile/profile.component.ts +++ b/src/app/features/profile/profile.component.ts @@ -1,6 +1,15 @@ import { createDispatchMap, select } from '@ngxs/store'; -import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, OnInit, signal } from '@angular/core'; +import { + ChangeDetectionStrategy, + Component, + computed, + DestroyRef, + inject, + OnDestroy, + OnInit, + signal, +} from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ActivatedRoute, Router } from '@angular/router'; @@ -23,7 +32,7 @@ import { FetchUserProfile, ProfileSelectors, SetUserProfile } from './store'; changeDetection: ChangeDetectionStrategy.OnPush, imports: [ProfileInformationComponent, GlobalSearchComponent, LoadingSpinnerComponent], }) -export class ProfileComponent implements OnInit { +export class ProfileComponent implements OnInit, OnDestroy { private router = inject(Router); private route = inject(ActivatedRoute); private destroyRef = inject(DestroyRef); @@ -56,6 +65,10 @@ export class ProfileComponent implements OnInit { } } + ngOnDestroy(): void { + this.prerenderReady.setNotReady(); + } + toProfileSettings(): void { this.router.navigate(['settings/profile']); } From fb785bcf775b8c555389d100de7187d28bfd1512 Mon Sep 17 00:00:00 2001 From: nsemets Date: Fri, 12 Dec 2025 11:44:18 +0200 Subject: [PATCH 3/3] fix(profile): updated unit tests --- src/app/features/profile/profile.component.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/features/profile/profile.component.spec.ts b/src/app/features/profile/profile.component.spec.ts index 484834991..451e2c6e2 100644 --- a/src/app/features/profile/profile.component.spec.ts +++ b/src/app/features/profile/profile.component.spec.ts @@ -3,6 +3,7 @@ import { MockComponents, MockProvider } from 'ng-mocks'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ActivatedRoute, Router } from '@angular/router'; +import { PrerenderReadyService } from '@core/services/prerender-ready.service'; import { UserSelectors } from '@core/store/user'; import { GlobalSearchComponent } from '@osf/shared/components/global-search/global-search.component'; import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component'; @@ -36,6 +37,7 @@ describe('ProfileComponent', () => { providers: [ MockProvider(Router, routerMock), MockProvider(ActivatedRoute, activatedRouteMock), + MockProvider(PrerenderReadyService), provideMockStore({ signals: [ { selector: UserSelectors.getCurrentUser, value: null },