updated loadingState computing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Component, inject, signal, DestroyRef, Signal } from '@angular/core';
|
||||
import { Component, inject, signal, DestroyRef, computed } from '@angular/core';
|
||||
import { Router, RouterLink, ActivatedRoute } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
@@ -11,10 +11,10 @@ import { MatInputModule } from '@angular/material/input';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { ResolverStateService } from '../../shared/services/resolver-state.service';
|
||||
|
||||
import {
|
||||
CustomAuthor,
|
||||
DehydratedInstitution,
|
||||
PersonsService,
|
||||
InstitutionsService,
|
||||
} from '../../api';
|
||||
@@ -36,15 +36,7 @@ import {
|
||||
MatAutocompleteModule,
|
||||
MatAutocompleteSelectedEvent,
|
||||
} from '@angular/material/autocomplete';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { SkTextDirective } from '../../custom-directives/sk-text.directive';
|
||||
import {
|
||||
NavigationError,
|
||||
NavigationEnd,
|
||||
NavigationStart,
|
||||
NavigationCancel,
|
||||
} from '@angular/router';
|
||||
import { createLoadError } from '../../shared/utils/errorHandler';
|
||||
|
||||
@Component({
|
||||
selector: 'app-person-list',
|
||||
@@ -77,10 +69,13 @@ export class PersonListComponent {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
public readonly state = inject(SharedStateService);
|
||||
public readonly paginationService = inject(PaginationService);
|
||||
public readonly resolverStateService = inject(ResolverStateService);
|
||||
private readonly defaultIncludes =
|
||||
'display_name,works_count,cited_by_count,topics,orcid,relevance_rating,last_known_institutions,affiliations';
|
||||
|
||||
readonly loadingState = signal<boolean>(false);
|
||||
readonly loadingState = computed(() =>
|
||||
this.resolverStateService.isResolvingInside('/persons'),
|
||||
);
|
||||
persons: CustomAuthor[] = [];
|
||||
total = 0;
|
||||
currentPage = 1;
|
||||
@@ -124,22 +119,6 @@ export class PersonListComponent {
|
||||
// Bookmarking
|
||||
bookmarkedIds = new Set<string>();
|
||||
constructor() {
|
||||
this.router.events
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((event) => {
|
||||
if (event instanceof NavigationStart) {
|
||||
this.loadingState.set(true);
|
||||
}
|
||||
|
||||
if (
|
||||
event instanceof NavigationEnd ||
|
||||
event instanceof NavigationCancel ||
|
||||
event instanceof NavigationError
|
||||
) {
|
||||
this.loadingState.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.institutionControl.value) {
|
||||
this.yearFilterEnabledControl.disable();
|
||||
}
|
||||
@@ -185,7 +164,6 @@ export class PersonListComponent {
|
||||
this.sortOrderControl.setValue(sortOrder, { emitEvent: false });
|
||||
this.updateSortOrderState(this.sortValueControl.value);
|
||||
}
|
||||
|
||||
|
||||
// Sync search box & institution input
|
||||
if (this.searchValue() !== query) {
|
||||
@@ -220,9 +198,8 @@ export class PersonListComponent {
|
||||
.subscribe(({ persons }) => {
|
||||
this.persons = (persons.results ?? []) as CustomAuthor[];
|
||||
this.total = persons.meta?.count;
|
||||
this.loadingState.set(false);
|
||||
});
|
||||
|
||||
|
||||
// listen for sorting selectors changes
|
||||
this.sortValueControl.valueChanges
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
|
||||
@@ -15,12 +15,6 @@ export class ResolverStateService {
|
||||
readonly previousUrl = signal<string | null>(null);
|
||||
|
||||
readonly isResolving = computed(() => this.resolvingUrl() !== null);
|
||||
readonly isResolvingPersonsFromOutside = computed(() => {
|
||||
const from = this.previousUrl();
|
||||
const to = this.resolvingUrl();
|
||||
if (!to?.startsWith('/persons')) return false;
|
||||
return !from?.startsWith('/persons'); // came from outside
|
||||
});
|
||||
|
||||
constructor() {
|
||||
this.router.events.subscribe((event) => {
|
||||
@@ -38,4 +32,19 @@ export class ResolverStateService {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isResolvingFromOutside(path: string) {
|
||||
const from = this.previousUrl();
|
||||
const to = this.resolvingUrl();
|
||||
if (!to?.startsWith(path)) return false;
|
||||
return !from?.startsWith(path); // came from outside
|
||||
}
|
||||
|
||||
isResolvingInside(path: string) {
|
||||
const from = this.previousUrl();
|
||||
const to = this.resolvingUrl();
|
||||
console.log(from, to, to?.startsWith(path) && from?.startsWith(path));
|
||||
if (to?.startsWith(path) && from?.startsWith(path)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user