Skip to content
Permalink
Browse files
fix(fulltext-search): updates the projects list when a new project is…
… created (#586)

Co-authored-by: André Kilchenmann <github@milchkannen.ch>
  • Loading branch information
mdelez and kilchenmann committed Nov 12, 2021
1 parent 9d7ffea commit 43fcbfa55efdfd85746d00eec5e1793d0c0c20f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
@@ -37,5 +37,6 @@ export class EmitEvent {
// possible events that can be emitted.
export enum Events {
loginSuccess,
gravSearchExecuted
gravSearchExecuted,
projectCreated
}
@@ -14,6 +14,7 @@ import { CacheService } from 'src/app/main/cache/cache.service';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service';
import { Session, SessionService } from 'src/app/main/services/session.service';
import { SortingService } from 'src/app/main/services/sorting.service';

@@ -84,7 +85,8 @@ export class ProjectsListComponent implements OnInit {
private _dialog: MatDialog,
private _router: Router,
private _session: SessionService,
private _sortingService: SortingService
private _sortingService: SortingService,
private _componentCommsService: ComponentCommunicationEventService
) { }

ngOnInit() {
@@ -165,6 +167,10 @@ export class ProjectsListComponent implements OnInit {
} else {
// update the view
this.refreshParent.emit();

if (mode === 'createProject') {
this._componentCommsService.emit(new EmitEvent(Events.projectCreated, true));
}
}
});
}
@@ -108,7 +108,7 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy {

projectIri: string;

componentCommsSubscription: Subscription;
componentCommsSubscriptions: Subscription[]= [];

// in case of an (api) error
error: any;
@@ -169,10 +169,17 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy {
}

// in the event of a grav search (advanced or expert search), clear the input field
this.componentCommsSubscription = this._componentCommsService.on(
this.componentCommsSubscriptions.push(this._componentCommsService.on(
Events.gravSearchExecuted, () => {
this.searchQuery = null;
});
})
);

this.componentCommsSubscriptions.push(this._componentCommsService.on(
Events.projectCreated, () => {
this.getAllProjects();
}
));
}

ngOnChanges() {
@@ -190,9 +197,9 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnDestroy() {
// unsubscribe from the componentCommsSubscription when component is destroyed
if (this.componentCommsSubscription !== undefined) {
this.componentCommsSubscription.unsubscribe();
// unsubscribe from all subscriptions incomponentCommsSubscriptions when component is destroyed
if (this.componentCommsSubscriptions !== undefined) {
this.componentCommsSubscriptions.forEach(sub => sub.unsubscribe());
}
}

0 comments on commit 43fcbfa

Please sign in to comment.