Merge pull request #3949 from NoelDeMartin/MOBILE-4524

MOBILE-4524 search: Optimize WS calls
main
Dani Palou 2024-02-29 10:34:35 +01:00 committed by GitHub
commit 0c49a451f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 13 deletions

View File

@ -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',

View File

@ -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;
}

View File

@ -45,7 +45,7 @@ export interface CoreBlockHandler extends CoreDelegateHandler {
block: CoreCourseBlock,
contextLevel: string,
instanceId: number,
): undefined | CoreBlockHandlerData | Promise<CoreBlockHandlerData>;
): undefined | CoreBlockHandlerData | Promise<undefined | CoreBlockHandlerData>;
}
/**