Skip to content

Commit f331bc2

Browse files
authored
[ENG-9943] Make prerenderReady work for user pages (#820)
- Ticket: [ENG-9943] - Feature flag: n/a ## Summary of Changes 1. Added prerender service to set prerender true.
1 parent f7ac060 commit f331bc2

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/app/features/profile/profile.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MockComponents, MockProvider } from 'ng-mocks';
33
import { ComponentFixture, TestBed } from '@angular/core/testing';
44
import { ActivatedRoute, Router } from '@angular/router';
55

6+
import { PrerenderReadyService } from '@core/services/prerender-ready.service';
67
import { UserSelectors } from '@core/store/user';
78
import { GlobalSearchComponent } from '@osf/shared/components/global-search/global-search.component';
89
import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component';
@@ -36,6 +37,7 @@ describe('ProfileComponent', () => {
3637
providers: [
3738
MockProvider(Router, routerMock),
3839
MockProvider(ActivatedRoute, activatedRouteMock),
40+
MockProvider(PrerenderReadyService),
3941
provideMockStore({
4042
signals: [
4143
{ selector: UserSelectors.getCurrentUser, value: null },

src/app/features/profile/profile.component.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import { 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';
413
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
514
import { ActivatedRoute, Router } from '@angular/router';
615

16+
import { PrerenderReadyService } from '@core/services/prerender-ready.service';
717
import { UserSelectors } from '@core/store/user';
818
import { GlobalSearchComponent } from '@osf/shared/components/global-search/global-search.component';
919
import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component';
1020
import { SEARCH_TAB_OPTIONS } from '@osf/shared/constants/search-tab-options.const';
1121
import { ResourceType } from '@osf/shared/enums/resource-type.enum';
22+
import { UserModel } from '@osf/shared/models/user/user.models';
1223
import { SetDefaultFilterValue } from '@osf/shared/stores/global-search';
13-
import { UserModel } from '@shared/models/user/user.models';
1424

1525
import { ProfileInformationComponent } from './components';
1626
import { 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

Comments
 (0)