+ [routerLink]="['/search', corpus.definition.name]"
+ [class.is-loading]="loading$ | async">
Search corpus
diff --git a/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts b/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts
index 08d4befa7..733afa348 100644
--- a/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts
+++ b/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts
@@ -4,7 +4,7 @@ import { APIIndexHealth, isComplete, JobStatus } from '@models/indexing';
import { ApiService, CorpusService } from '@services';
import { actionIcons } from '@shared/icons';
import * as _ from 'lodash';
-import { map, Subject, switchMap, merge, filter } from 'rxjs';
+import { map, Subject, switchMap, merge, filter, BehaviorSubject } from 'rxjs';
/** Possible states for the interface of this component */
type DisplayState = {
@@ -85,9 +85,11 @@ export class IndexFormComponent implements OnChanges, OnDestroy {
state$ = new Subject
;
destroy$ = new Subject();
+ loading$ = new BehaviorSubject(false);
actionIcons = actionIcons;
+
private jobID: number;
private stopping$ = new Subject();
@@ -138,7 +140,8 @@ export class IndexFormComponent implements OnChanges, OnDestroy {
toggleCorpusActive() {
this.corpus.active = !this.corpus.active;
- this.corpus.save();
+ this.loading$.next(true);
+ this.corpus.save().subscribe(() => this.loading$.next(false));
}
stateClass(state: DisplayState) {
diff --git a/frontend/src/app/models/corpus-definition.ts b/frontend/src/app/models/corpus-definition.ts
index 01b578e8b..4bb4ef45e 100644
--- a/frontend/src/app/models/corpus-definition.ts
+++ b/frontend/src/app/models/corpus-definition.ts
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import { ApiService, CorpusService } from '@services';
-import { BehaviorSubject, Observable } from 'rxjs';
-import { filter, share, switchMap, tap } from 'rxjs/operators';
+import { BehaviorSubject, from, Observable } from 'rxjs';
+import { delayWhen, filter, shareReplay, tap } from 'rxjs/operators';
import { findByName } from '@app/utils/utils';
export type Delimiter = ',' | ';' | '\t';
@@ -153,15 +153,13 @@ export class CorpusDefinition {
const request$ = this.id
? this.apiService.updateCorpus(this.id, data)
: this.apiService.createCorpus(data);
- const result$ = request$.pipe(share());
-
- result$.subscribe((result) => this.setFromAPIData(result));
- // refresh corpus data if applicable
- result$.pipe(
- switchMap(() => this.requireCorpusRefresh()),
- filter(_.identity)
- ).subscribe(() => this.corpusService.get(true));
+ const result$ = request$.pipe(
+ tap(result => this.setFromAPIData(result)),
+ delayWhen(() => this.refreshCorpora()),
+ shareReplay(1),
+ );
+ result$.subscribe(); // subscribe to execute request(s)
return result$;
}
@@ -200,6 +198,13 @@ export class CorpusDefinition {
}
return Promise.resolve(false);
}
+
+ /** refresh searchable corpora if needed */
+ private refreshCorpora(): Observable {
+ return from(this.requireCorpusRefresh().then(
+ refresh => refresh ? this.corpusService.get(refresh) : Promise.resolve(undefined)
+ ));
+ }
};
export const FIELD_TYPE_OPTIONS: {