Skip to content

Mobile 4802 #4405

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/components/dynamic-component/dynamic-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class CoreDynamicComponent<ComponentClass> implements OnChanges, DoCheck,
setTimeout(() => this.createComponent());
}

protected promisedInstance = new CorePromisedValue<any>(); // eslint-disable-line @typescript-eslint/no-explicit-any
promisedInstance = new CorePromisedValue<any>(); // eslint-disable-line @typescript-eslint/no-explicit-any

container?: ViewContainerRef;

Expand Down
8 changes: 3 additions & 5 deletions src/core/features/block/components/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { Component, Input, ViewChild, OnDestroy, Type, OnChanges, SimpleChanges } from '@angular/core';
import { Component, Input, OnDestroy, Type, OnChanges, SimpleChanges, viewChild, Signal } from '@angular/core';
import { CoreBlockDelegate } from '../../services/block-delegate';
import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component';
import { Subscription } from 'rxjs';
Expand All @@ -35,7 +35,7 @@ import { CoreSharedModule } from '@/core/shared.module';
})
export class CoreBlockComponent implements OnChanges, OnDestroy {

@ViewChild(CoreDynamicComponent) dynamicComponent?: CoreDynamicComponent<ICoreBlockComponent>;
dynamicComponent: Signal<CoreDynamicComponent<ICoreBlockComponent> | undefined> = viewChild(CoreDynamicComponent);

@Input({ required: true }) block!: CoreCourseBlock; // The block to render.
@Input({ required: true }) contextLevel!: ContextLevel; // The context where the block will be used.
Expand Down Expand Up @@ -119,9 +119,7 @@ export class CoreBlockComponent implements OnChanges, OnDestroy {
* @returns Promise resolved when done.
*/
async invalidate(): Promise<void> {
if (this.dynamicComponent) {
await this.dynamicComponent.callComponentMethod('invalidateContent');
}
await this.dynamicComponent()?.callComponentMethod('invalidateContent');
}

}
14 changes: 10 additions & 4 deletions src/core/features/courses/pages/my/my.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { AddonBlockMyOverviewComponent } from '@addons/block/myoverview/components/myoverview/myoverview';
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Component, effect, OnDestroy, OnInit, viewChild } from '@angular/core';
import { AsyncDirective } from '@classes/async-directive';
import { PageLoadsManager } from '@classes/page-loads-manager';
import { CorePromisedValue } from '@classes/promised-value';
Expand Down Expand Up @@ -59,7 +59,7 @@ import { CoreCoursesMyPageName } from '@features/courses/constants';
})
export default class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirective {

@ViewChild(CoreBlockComponent) block!: CoreBlockComponent;
block = viewChild(CoreBlockComponent);

downloadCoursesEnabled = false;
userId: number;
Expand Down Expand Up @@ -87,6 +87,14 @@ export default class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirect
this.loadContent();
});

effect(async () => {
const dynamicComponent = this.block()?.dynamicComponent();

if (dynamicComponent) {
this.myOverviewBlock = await dynamicComponent.promisedInstance;
}
});

this.logView = CoreTime.once(async () => {
await CorePromiseUtils.ignoreErrors(CoreCourses.logView('my'));

Expand Down Expand Up @@ -138,8 +146,6 @@ export default class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirect

await CoreWait.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.
Expand Down