fix/blocking_bio #225

Merged
tischer merged 2 commits from fix/blocking_bio into dev 2026-07-17 19:57:21 +02:00
3 changed files with 46 additions and 15 deletions
@@ -18,12 +18,13 @@ import {
RouterModule,
RouterOutlet,
} from '@angular/router';
import { of, switchMap, finalize, map, catchError } from 'rxjs';
import { of, switchMap, finalize, map, catchError, combineLatest } from 'rxjs';
import { PersonInterestingComponent } from '../person-interesting/person-interesting.component';
import { WorksService } from '../../api';
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
import { PersonBioResolved } from '../../resolvers/person-bio.resolver';
import { PersonDataResolved } from '../../resolvers/person.resolver';
import { BookmarkService } from '../../shared/services/bookmark.service';
@Component({
@@ -101,8 +102,17 @@ export class PersonComponent {
readonly person = toSignal(
this.activatedRoute.data.pipe(
map(({ personData }) => {
return personData?.results[0] ?? null;
switchMap((data) => {
const resolved = data['personData'] as PersonDataResolved | undefined;
if (!resolved) {
this.isPersonLoading.set(false);
return of(null);
}
this.isPersonLoading.set(true);
return resolved.personData$.pipe(
map((response) => response?.results?.[0] ?? null),
finalize(() => this.isPersonLoading.set(false)),
);
}),
),
{ initialValue: null },
@@ -118,8 +128,12 @@ export class PersonComponent {
}
readonly personBio = toSignal(
this.activatedRoute.data.pipe(
switchMap((data) => {
combineLatest([this.activatedRoute.data, toObservable(this.person)]).pipe(
switchMap(([data, person]) => {
if (!person) {
this.isBioLoading.set(false);
return of(null);
}
const resolved = data['personBio'] as PersonBioResolved | undefined;
if (!resolved) {
this.isBioLoading.set(false);
@@ -216,9 +230,13 @@ export class PersonComponent {
readonly isTopicsLoading = signal(false);
readonly primaryTopicCounts = toSignal(
toObservable(this.authorId).pipe(
switchMap((id) => {
if (!id) return of([]);
toObservable(this.person).pipe(
switchMap((person) => {
const id = this.authorId();
if (!person || !id) {
this.isTopicsLoading.set(false);
return of([]);
}
this.isTopicsLoading.set(true);
return this.worksApi.getPrimaryTopicCountsByAuthor(id).pipe(
catchError((err) => {
@@ -1,6 +1,6 @@
import { ResolveFn } from '@angular/router';
import { inject } from '@angular/core';
import { Observable, of, map, catchError } from 'rxjs';
import { Observable, of, map, catchError, shareReplay } from 'rxjs';
import { PersonsService } from '../api';
export interface PersonBioResolved {
@@ -21,6 +21,7 @@ export const personBioResolver: ResolveFn<PersonBioResolved> = (route) => {
console.error('Failed to load bio:', err);
return of(null);
}),
shareReplay(1),
);
return { bio$ };
+18 -6
View File
@@ -1,11 +1,13 @@
import { ResolveFn } from '@angular/router';
import { inject } from '@angular/core';
import { CustomAuthorsListResponse, PersonsService } from '../api';
import { Observable, of, catchError, shareReplay } from 'rxjs';
export const personResolver: ResolveFn<CustomAuthorsListResponse> = (
route,
state,
) => {
export interface PersonDataResolved {
personData$: Observable<CustomAuthorsListResponse | null>;
}
export const personResolver: ResolveFn<PersonDataResolved> = (route, state) => {
const PERSON_INCLUDE_TAGS =
'display_name,works_count,cited_by_count,summary_stats,ids,' +
'last_known_institutions,affiliations,topics,orcid,' +
@@ -16,8 +18,18 @@ export const personResolver: ResolveFn<CustomAuthorsListResponse> = (
const personsService = inject(PersonsService);
if (!authorId) {
return { results: [] };
return { personData$: of(null) };
}
return personsService.getPersonByID(authorId, PERSON_INCLUDE_TAGS);
const personData$ = personsService
.getPersonByID(authorId, PERSON_INCLUDE_TAGS)
.pipe(
catchError((err) => {
console.error('Failed to load person data:', err);
return of(null);
}),
shareReplay(1),
);
return { personData$ };
};