Skip to content

Commit

Permalink
Merge pull request #3949 from NoelDeMartin/MOBILE-4524
Browse files Browse the repository at this point in the history
MOBILE-4524 search: Optimize WS calls
  • Loading branch information
dpalou authored Feb 29, 2024
2 parents 5d3e8db + 1e3eed6 commit 0c49a45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions src/addons/block/searchforums/services/block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,28 @@ export class AddonBlockSearchForumsHandlerService extends CoreBlockBaseHandler {
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
const enabled = await CoreSearchGlobalSearch.isEnabled();

if (!enabled) {
return false;
}

const forumSearchAreas = ['mod_forum-activity', 'mod_forum-post'];
const searchAreas = await CoreSearchGlobalSearch.getSearchAreas();

return searchAreas.some(({ id }) => forumSearchAreas.includes(id));
return CoreSearchGlobalSearch.isEnabled();
}

/**
* @inheritdoc
*/
getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData | undefined {
async getDisplayData(
block: CoreCourseBlock,
contextLevel: string,
instanceId: number,
): Promise<undefined | CoreBlockHandlerData> {
if (contextLevel !== 'course') {
return;
}

const forumSearchAreas = ['mod_forum-activity', 'mod_forum-post'];
const searchAreas = await CoreSearchGlobalSearch.getSearchAreas();

if (!searchAreas.some(({ id }) => forumSearchAreas.includes(id))) {
return;
}

return {
title: 'addon.block_searchforums.pluginname',
class: 'addon-block-search-forums',
Expand Down
2 changes: 1 addition & 1 deletion src/core/features/block/classes/base-block-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class CoreBlockBaseHandler implements CoreBlockHandler {
block: CoreCourseBlock, // eslint-disable-line @typescript-eslint/no-unused-vars
contextLevel: string, // eslint-disable-line @typescript-eslint/no-unused-vars
instanceId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
): undefined | CoreBlockHandlerData | Promise<CoreBlockHandlerData> {
): undefined | CoreBlockHandlerData | Promise<undefined | CoreBlockHandlerData> {
// To be overridden.
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/features/block/services/block-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface CoreBlockHandler extends CoreDelegateHandler {
block: CoreCourseBlock,
contextLevel: string,
instanceId: number,
): undefined | CoreBlockHandlerData | Promise<CoreBlockHandlerData>;
): undefined | CoreBlockHandlerData | Promise<undefined | CoreBlockHandlerData>;
}

/**
Expand Down

0 comments on commit 0c49a45

Please sign in to comment.