Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-4091 mycourses: Fix mypage error and empty page #3314

Merged
merged 1 commit into from Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/classes/site.ts
Expand Up @@ -95,7 +95,7 @@ export class CoreSite {
'3.9': 2020061500,
'3.10': 2020110900,
'3.11': 2021051700,
'4.0': 2021100300, // @todo [4.0] replace with right value when released. Using a tmp value to be able to test new things.
'4.0': 2022041900,
};

// Possible cache update frequencies.
Expand Down
4 changes: 3 additions & 1 deletion src/core/features/block/services/block-delegate.ts
Expand Up @@ -194,7 +194,9 @@ export class CoreBlockDelegateService extends CoreDelegate<CoreBlockHandler> {
* @return Whether is enabled or disabled in site.
*/
protected isFeatureDisabled(handler: CoreBlockHandler, site: CoreSite): boolean {
return this.areBlocksDisabledInSite(site) || super.isFeatureDisabled(handler, site);
// Allow displaying my overview even if all blocks are disabled, to avoid having an empty My Courses.
return (this.areBlocksDisabledInSite(site) && handler.blockName !== 'myoverview') ||
super.isFeatureDisabled(handler, site);
}

/**
Expand Down
20 changes: 16 additions & 4 deletions src/core/features/courses/pages/my/my.ts
Expand Up @@ -15,6 +15,7 @@
import { AddonBlockMyOverviewComponent } from '@addons/block/myoverview/components/myoverview/myoverview';
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { CoreBlockComponent } from '@features/block/components/block/block';
import { CoreBlockDelegate } from '@features/block/services/block-delegate';
import { CoreCourseBlock } from '@features/course/services/course';
import { CoreCoursesDashboard, CoreCoursesDashboardProvider } from '@features/courses/services/dashboard';
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
Expand Down Expand Up @@ -80,28 +81,39 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
const available = await CoreCoursesDashboard.isAvailable();
const disabled = await CoreCourses.isMyCoursesDisabled();

const supportsMyParam = !!CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.0');

if (available && !disabled) {
try {
const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, undefined, this.myPageCourses);
const blocks = await CoreCoursesDashboard.getDashboardBlocks(
undefined,
undefined,
supportsMyParam ? this.myPageCourses : undefined,
);

// My overview block should always be in main blocks, but check side blocks too just in case.
this.loadedBlock = blocks.mainBlocks.concat(blocks.sideBlocks).find((block) => block.name == 'myoverview');
this.hasSideBlocks = blocks.sideBlocks.length > 0;
this.hasSideBlocks = supportsMyParam && CoreBlockDelegate.hasSupportedBlock(blocks.sideBlocks);

await CoreUtils.nextTicks(2);

this.myOverviewBlock = this.block?.dynamicComponent?.instance as AddonBlockMyOverviewComponent;

if (!this.loadedBlock && !supportsMyParam) {
// In old sites, display the block even if not found in Dashboard.
// This is because the "My courses" page doesn't exist in the site so it can't be configured.
this.loadFallbackBlock();
}
} catch (error) {
CoreDomUtils.showErrorModal(error);

// Cannot get the blocks, just show the block if needed.
this.loadFallbackBlock();
}
} else if (!available) {
// WS not available, or my courses page not available. show fallback block.
// WS not available, show fallback block.
this.loadFallbackBlock();
} else {
// Disabled.
this.loadedBlock = undefined;
}

Expand Down