From ce86bb42f17bb063c7d2572ab1e978fefeb98806 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 15 Apr 2024 14:13:29 +0200 Subject: [PATCH] MOBILE-4573 forum: Hide search when disabled --- .../mod/forum/components/index/index.html | 2 +- .../mod/forum/components/index/index.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/addons/mod/forum/components/index/index.html b/src/addons/mod/forum/components/index/index.html index e2a0e5fe9..20bfbdbec 100644 --- a/src/addons/mod/forum/components/index/index.html +++ b/src/addons/mod/forum/components/index/index.html @@ -1,6 +1,6 @@ - + diff --git a/src/addons/mod/forum/components/index/index.ts b/src/addons/mod/forum/components/index/index.ts index f3fd74957..a9d01945e 100644 --- a/src/addons/mod/forum/components/index/index.ts +++ b/src/addons/mod/forum/components/index/index.ts @@ -59,6 +59,7 @@ import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/ import { CorePromisedValue } from '@classes/promised-value'; import { CoreNavigator } from '@services/navigator'; import { ADDON_MOD_FORUM_SEARCH_PAGE_NAME } from '@addons/mod/forum/constants'; +import { CoreSearchGlobalSearch } from '@features/search/services/global-search'; /** * Component that displays a forum entry page. */ @@ -85,6 +86,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom hasOfflineRatings = false; showQAMessage = false; isSetPinAvailable = false; + showSearch = false; sortOrderSelectorModalOptions: ModalOptions = { component: AddonModForumSortOrderSelectorComponent, }; @@ -306,6 +308,9 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom this.hasOffline = this.hasOffline || this.hasOfflineRatings; } }); + + // Initialize search. + this.showSearch = await this.isSearchEnabled(); } async ngAfterViewInit(): Promise { @@ -690,6 +695,21 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom } } + /** + * Check if forum search is available. + * + * @returns Whether forum search is available. + */ + protected async isSearchEnabled(): Promise { + if (!CoreSearchGlobalSearch.isEnabled()) { + return false; + } + + const searchAreas = await CoreSearchGlobalSearch.getSearchAreas(); + + return !!searchAreas.find(({ id }) => id === 'mod_forum-post'); + } + } /**