Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[USH-1677 TEST]Changing status on a post in map-view doesn't update the UI to reflect the change #1501

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,57 @@
import { Injectable, OnInit } from '@angular/core';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { EventBusService, EventType } from './event-bus.service';

@UntilDestroy()
@Injectable({
providedIn: 'root',
})
export class EventTrackerService implements OnInit {
public action: EventType;
public response: any;
public updateById: boolean | undefined;
constructor(private eventBusService: EventBusService) {}

// eslint-disable-next-line @angular-eslint/contextual-lifecycle
ngOnInit() {
console.log('OnInit: Let my people go...');
// this.emit({ payload })
// this.trigger({ action: this.action, updateById: this.updateById });
}

// setTrigger({ action, updateById }: { action: EventType; updateById?: boolean }) {

// }

public trigger({ action, updateById }: { action: EventType; updateById?: boolean }) {
this.action = action;
this.updateById = updateById;

this.eventBusService
.on(this.action)
.pipe(untilDestroyed(this))
.subscribe({
next: (response) => {
console.log(response);
console.log(this.action);
this.action = action;
this.response = response;
this.updateById = updateById;
const setResponse = () => (this.response = response);
if (updateById) {
if (this.response.id === response.id) setResponse();
} else {
setResponse();
}
},
});
}

public emit({ payload }: { payload: any }) {
console.log(this.action, payload);
this.eventBusService.next({
type: this.action,
payload,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BaseComponent } from '../../base.component';
import { ShareModalComponent } from '../../shared/components';
import { PostResult, PostsService, PostStatus, postHelpers } from '@mzima-client/sdk';
import { ConfirmModalService } from '../../core/services/confirm-modal.service';
import { EventTrackerService } from '../../core/services/event-tracker.service';

@Component({
selector: 'app-post-head',
Expand Down Expand Up @@ -35,6 +36,7 @@ export class PostHeadComponent extends BaseComponent implements OnInit {
private translate: TranslateService,
private eventBusService: EventBusService,
private snackBar: MatSnackBar,
private eventTrackerService: EventTrackerService,
) {
super(sessionService, breakpointService);
this.checkDesktop();
Expand Down Expand Up @@ -81,7 +83,7 @@ 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.eventTrackerService.emit({ 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,5 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { PostPropertiesInterface, PostResult } from '@mzima-client/sdk';
import { EventTrackerService } from '../../core/services/event-tracker.service';
import { EventType } from '@services';

@Component({
selector: 'app-post-metadata',
Expand All @@ -10,8 +12,11 @@ export class PostMetadataComponent implements OnInit {
@Input() post: PostResult | PostPropertiesInterface;
author: string;

constructor(private eventTrackerService: EventTrackerService) {}

ngOnInit(): void {
this.getUsername();
this.eventTrackerService.trigger({ action: EventType.StatusChange, updateById: true });
}

private getUsername(): void {
Expand Down
Loading