11import { createDispatchMap , select } from '@ngxs/store' ;
22
3- import { ChangeDetectionStrategy , Component , computed , DestroyRef , inject , OnInit , signal } from '@angular/core' ;
3+ import {
4+ ChangeDetectionStrategy ,
5+ Component ,
6+ computed ,
7+ DestroyRef ,
8+ inject ,
9+ OnDestroy ,
10+ OnInit ,
11+ signal ,
12+ } from '@angular/core' ;
413import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
514import { ActivatedRoute , Router } from '@angular/router' ;
615
16+ import { PrerenderReadyService } from '@core/services/prerender-ready.service' ;
717import { UserSelectors } from '@core/store/user' ;
818import { GlobalSearchComponent } from '@osf/shared/components/global-search/global-search.component' ;
919import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component' ;
1020import { SEARCH_TAB_OPTIONS } from '@osf/shared/constants/search-tab-options.const' ;
1121import { ResourceType } from '@osf/shared/enums/resource-type.enum' ;
22+ import { UserModel } from '@osf/shared/models/user/user.models' ;
1223import { SetDefaultFilterValue } from '@osf/shared/stores/global-search' ;
13- import { UserModel } from '@shared/models/user/user.models' ;
1424
1525import { ProfileInformationComponent } from './components' ;
1626import { FetchUserProfile , ProfileSelectors , SetUserProfile } from './store' ;
@@ -22,20 +32,22 @@ import { FetchUserProfile, ProfileSelectors, SetUserProfile } from './store';
2232 changeDetection : ChangeDetectionStrategy . OnPush ,
2333 imports : [ ProfileInformationComponent , GlobalSearchComponent , LoadingSpinnerComponent ] ,
2434} )
25- export class ProfileComponent implements OnInit {
35+ export class ProfileComponent implements OnInit , OnDestroy {
2636 private router = inject ( Router ) ;
2737 private route = inject ( ActivatedRoute ) ;
2838 private destroyRef = inject ( DestroyRef ) ;
39+ private readonly prerenderReady = inject ( PrerenderReadyService ) ;
40+
2941 private actions = createDispatchMap ( {
3042 fetchUserProfile : FetchUserProfile ,
3143 setDefaultFilterValue : SetDefaultFilterValue ,
3244 setUserProfile : SetUserProfile ,
3345 } ) ;
3446
35- private loggedInUser = select ( UserSelectors . getCurrentUser ) ;
36- private userProfile = select ( ProfileSelectors . getUserProfile ) ;
37-
47+ loggedInUser = select ( UserSelectors . getCurrentUser ) ;
48+ userProfile = select ( ProfileSelectors . getUserProfile ) ;
3849 isUserLoading = select ( ProfileSelectors . isUserProfileLoading ) ;
50+
3951 resourceTabOptions = SEARCH_TAB_OPTIONS . filter ( ( x ) => x . value !== ResourceType . Agent ) ;
4052
4153 isMyProfile = computed ( ( ) => ! this . route . snapshot . params [ 'id' ] ) ;
@@ -53,6 +65,10 @@ export class ProfileComponent implements OnInit {
5365 }
5466 }
5567
68+ ngOnDestroy ( ) : void {
69+ this . prerenderReady . setNotReady ( ) ;
70+ }
71+
5672 toProfileSettings ( ) : void {
5773 this . router . navigate ( [ 'settings/profile' ] ) ;
5874 }
@@ -66,17 +82,23 @@ export class ProfileComponent implements OnInit {
6682
6783 private setupMyProfile ( user : UserModel ) : void {
6884 this . actions . setUserProfile ( user ) ;
85+
6986 if ( user ?. iri ) {
7087 this . actions . setDefaultFilterValue ( 'creator,isContainedBy.creator' , user . iri ) ;
7188 this . defaultSearchFiltersInitialized . set ( true ) ;
7289 }
90+
91+ this . prerenderReady . setReady ( ) ;
7392 }
7493
7594 private setSearchFilter ( ) : void {
7695 const currentUser = this . user ( ) ;
96+
7797 if ( currentUser ?. iri ) {
7898 this . actions . setDefaultFilterValue ( 'creator,isContainedBy.creator' , currentUser . iri ) ;
7999 this . defaultSearchFiltersInitialized . set ( true ) ;
80100 }
101+
102+ this . prerenderReady . setReady ( ) ;
81103 }
82104}
0 commit comments