Skip to content

Commit

Permalink
Merge pull request #4013 from NoelDeMartin/MOBILE-4573
Browse files Browse the repository at this point in the history
MOBILE-4573 forum: Hide search when disabled
  • Loading branch information
dpalou authored Apr 17, 2024
2 parents a03937d + ce86bb4 commit 9f954c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/addons/mod/forum/components/index/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Buttons to add to the header. -->
<core-navbar-buttons slot="end">
<ion-button fill="clear" (click)="openSearch()" [attr.aria-label]="'core.search' | translate">
<ion-button fill="clear" *ngIf="showSearch" (click)="openSearch()" [attr.aria-label]="'core.search' | translate">
<ion-icon name="fas-magnifying-glass" slot="icon-only" aria-hidden="true" />
</ion-button>
<ion-button fill="clear" (click)="openModuleSummary()" aria-haspopup="true" [attr.aria-label]="'core.info' | translate">
Expand Down
20 changes: 20 additions & 0 deletions src/addons/mod/forum/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -85,6 +86,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
hasOfflineRatings = false;
showQAMessage = false;
isSetPinAvailable = false;
showSearch = false;
sortOrderSelectorModalOptions: ModalOptions = {
component: AddonModForumSortOrderSelectorComponent,
};
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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<boolean> {
if (!CoreSearchGlobalSearch.isEnabled()) {
return false;
}

const searchAreas = await CoreSearchGlobalSearch.getSearchAreas();

return !!searchAreas.find(({ id }) => id === 'mod_forum-post');
}

}

/**
Expand Down

0 comments on commit 9f954c8

Please sign in to comment.