Skip to content

Commit

Permalink
Fix: Use event bus to fix publish status change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifycode committed Dec 11, 2024
1 parent 74cbf81 commit a577e36
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const enum EventType {
RefreshSurveysCounters = 'REFRESH_SURVEYS_COUNTERS',
StopExportPolling = 'STOP_EXPORT_POLLING',
ExportDone = 'EXPORT_DONE',
StatusChange = 'STATUS_CHANGE',
}

export interface BusEvent<T = any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export class PostHeadComponent extends BaseComponent implements OnInit {
if (postHelpers.isAllRequiredCompleted(post)) {
this.postsService.updateStatus(this.post.id, PostStatus.Published).subscribe((res) => {
this.post = res.result;
this.statusChanged.emit();
this.eventBusService.next({
type: EventType.StatusChange,
payload: this.post,
});
});
} else {
this.showMessage(this.translate.instant('notify.post.unfinished_post_task'), 'error', 5000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, Input, OnInit } from '@angular/core';
import { PostPropertiesInterface, PostResult } from '@mzima-client/sdk';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { EventBusService, EventType } from '@services';

@UntilDestroy()
@Component({
selector: 'app-post-metadata',
templateUrl: './post-metadata.component.html',
Expand All @@ -10,8 +13,18 @@ export class PostMetadataComponent implements OnInit {
@Input() post: PostResult | PostPropertiesInterface;
author: string;

constructor(private eventBusService: EventBusService) {}

ngOnInit(): void {
this.getUsername();
this.eventBusService
.on(EventType.StatusChange)
.pipe(untilDestroyed(this))
.subscribe({
next: (post) => {
if (post.id === this.post.id) this.post = post;
},
});
}

private getUsername(): void {
Expand Down

0 comments on commit a577e36

Please sign in to comment.