From acbccacecaeb7633810f69c2f42555b8821a6c9e Mon Sep 17 00:00:00 2001 From: Ifycode Date: Tue, 3 Dec 2024 04:53:46 +0100 Subject: [PATCH 1/3] Fix: Add only parameters for categories in mobile --- .../map/components/filter/filter.component.ts | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/apps/mobile-mzima-client/src/app/map/components/filter/filter.component.ts b/apps/mobile-mzima-client/src/app/map/components/filter/filter.component.ts index 75cd9aca82..35ca40748f 100644 --- a/apps/mobile-mzima-client/src/app/map/components/filter/filter.component.ts +++ b/apps/mobile-mzima-client/src/app/map/components/filter/filter.component.ts @@ -1,6 +1,11 @@ import { Component, EventEmitter, Input, OnInit, Output, forwardRef } from '@angular/core'; import { FilterControl, FilterControlOption } from '@models'; -import { CategoriesService, CategoryInterface, SavedsearchesService } from '@mzima-client/sdk'; +import { + apiHelpers, + CategoriesService, + CategoryInterface, + SavedsearchesService, +} from '@mzima-client/sdk'; import { AlertService, NetworkService, SessionService, ToastService } from '@services'; import { searchFormHelper, getDeploymentAvatarPlaceholder } from '@helpers'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; @@ -198,31 +203,33 @@ export class FilterComponent implements ControlValueAccessor, OnInit { } private getCategories(): void { - this.categoriesService.get().subscribe({ - next: (response) => { - const mainCategories = response?.results.filter((c: CategoryInterface) => !c.parent_id); - this.options = mainCategories?.map((category: CategoryInterface) => ({ - checked: this.value.has(category.id), - value: category.id, - label: String(category.tag), - color: getDeploymentAvatarPlaceholder(String(category.tag)), - options: category.children.length - ? category.children.map((cat: CategoryInterface) => ({ - value: cat.id, - label: cat.tag, - checked: this.value.has(cat.id), - })) - : null, - isDropDownOpen: category.children.length ? false : null, - })); - this.isOptionsLoading = false; - }, - error: (err) => { - if (err.message.match(/Http failure response for/)) { - setTimeout(() => this.getCategories(), 5000); - } - }, - }); + this.categoriesService + .getCategories({ only: apiHelpers.ONLY.TAG_ID_PARENTID_CHILDREN }) + .subscribe({ + next: (response) => { + const mainCategories = response?.results.filter((c: CategoryInterface) => !c.parent_id); + this.options = mainCategories?.map((category: CategoryInterface) => ({ + checked: this.value.has(category.id), + value: category.id, + label: String(category.tag), + color: getDeploymentAvatarPlaceholder(String(category.tag)), + options: category.children.length + ? category.children.map((cat: CategoryInterface) => ({ + value: cat.id, + label: cat.tag, + checked: this.value.has(cat.id), + })) + : null, + isDropDownOpen: category.children.length ? false : null, + })); + this.isOptionsLoading = false; + }, + error: (err) => { + if (err.message.match(/Http failure response for/)) { + setTimeout(() => this.getCategories(), 5000); + } + }, + }); } public getObjectKeysCount(obj: any): number { From ac84e537ba5fc298add25adae2142eea0577f7ce Mon Sep 17 00:00:00 2001 From: Ifycode Date: Wed, 11 Dec 2024 12:52:56 +0100 Subject: [PATCH 2/3] Fix: Use event bus to fix publish status change --- .../src/app/core/services/event-bus.service.ts | 1 + .../src/app/post/post-head/post-head.component.ts | 5 ++++- .../post/post-metadata/post-metadata.component.ts | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/web-mzima-client/src/app/core/services/event-bus.service.ts b/apps/web-mzima-client/src/app/core/services/event-bus.service.ts index 4edcfbb07c..bd908a6542 100644 --- a/apps/web-mzima-client/src/app/core/services/event-bus.service.ts +++ b/apps/web-mzima-client/src/app/core/services/event-bus.service.ts @@ -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 { diff --git a/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts b/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts index eeb4597b60..9be9c779d5 100644 --- a/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts +++ b/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts @@ -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); diff --git a/apps/web-mzima-client/src/app/post/post-metadata/post-metadata.component.ts b/apps/web-mzima-client/src/app/post/post-metadata/post-metadata.component.ts index 4b3f1bd7c2..cac033441a 100644 --- a/apps/web-mzima-client/src/app/post/post-metadata/post-metadata.component.ts +++ b/apps/web-mzima-client/src/app/post/post-metadata/post-metadata.component.ts @@ -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', @@ -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 { From 41079aed2466a12fe6df8a55fb7939030e3a58be Mon Sep 17 00:00:00 2001 From: Ifycode Date: Wed, 11 Dec 2024 12:59:13 +0100 Subject: [PATCH 3/3] Fix: For archive and under review too --- .../src/app/post/post-head/post-head.component.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts b/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts index 9be9c779d5..7a000496ea 100644 --- a/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts +++ b/apps/web-mzima-client/src/app/post/post-head/post-head.component.ts @@ -72,7 +72,10 @@ export class PostHeadComponent extends BaseComponent implements OnInit { underReview() { this.postsService.updateStatus(this.post.id, PostStatus.Draft).subscribe((res) => { this.post = res.result; - this.statusChanged.emit(); + this.eventBusService.next({ + type: EventType.StatusChange, + payload: this.post, + }); }); } @@ -103,7 +106,10 @@ export class PostHeadComponent extends BaseComponent implements OnInit { archive() { this.postsService.updateStatus(this.post.id, PostStatus.Archived).subscribe((res) => { this.post = res.result; - this.statusChanged.emit(); + this.eventBusService.next({ + type: EventType.StatusChange, + payload: this.post, + }); }); }