Skip to content

Commit ab61286

Browse files
authored
Merge pull request #4405 from alfonso-salces/MOBILE-4802
Mobile 4802
2 parents 16af401 + b7ff674 commit ab61286

File tree

2 files changed

+14
-9
lines changed
  • src/core/features

2 files changed

+14
-9
lines changed

src/core/features/block/components/block/block.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Component, Input, ViewChild, OnDestroy, Type, OnChanges, SimpleChanges } from '@angular/core';
15+
import { Component, Input, OnDestroy, Type, OnChanges, SimpleChanges, viewChild } from '@angular/core';
1616
import { CoreBlockDelegate } from '../../services/block-delegate';
1717
import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component';
1818
import { Subscription } from 'rxjs';
@@ -34,7 +34,7 @@ import { CoreSharedModule } from '@/core/shared.module';
3434
})
3535
export class CoreBlockComponent implements OnChanges, OnDestroy {
3636

37-
@ViewChild(CoreDynamicComponent) dynamicComponent?: CoreDynamicComponent<ICoreBlockComponent>;
37+
readonly dynamicComponent = viewChild<CoreDynamicComponent<ICoreBlockComponent>>(CoreDynamicComponent);
3838

3939
@Input({ required: true }) block!: CoreCourseBlock; // The block to render.
4040
@Input({ required: true }) contextLevel!: ContextLevel; // The context where the block will be used.
@@ -118,9 +118,7 @@ export class CoreBlockComponent implements OnChanges, OnDestroy {
118118
* @returns Promise resolved when done.
119119
*/
120120
async invalidate(): Promise<void> {
121-
if (this.dynamicComponent) {
122-
await this.dynamicComponent.callComponentMethod('invalidateContent');
123-
}
121+
await this.dynamicComponent()?.callComponentMethod('invalidateContent');
124122
}
125123

126124
}

src/core/features/courses/pages/my/my.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import { AddonBlockMyOverviewComponent } from '@addons/block/myoverview/components/myoverview/myoverview';
16-
import { Component, OnDestroy, OnInit, ViewChild, inject } from '@angular/core';
16+
import { Component, effect, OnDestroy, OnInit, viewChild, inject } from '@angular/core';
1717
import { AsyncDirective } from '@classes/async-directive';
1818
import { PageLoadsManager } from '@classes/page-loads-manager';
1919
import { CorePromisedValue } from '@classes/promised-value';
@@ -58,7 +58,7 @@ import { CoreCoursesMyPageName } from '@features/courses/constants';
5858
})
5959
export default class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirective {
6060

61-
@ViewChild(CoreBlockComponent) block!: CoreBlockComponent;
61+
readonly block = viewChild(CoreBlockComponent);
6262

6363
downloadCoursesEnabled = false;
6464
userId: number;
@@ -87,6 +87,15 @@ export default class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirect
8787
this.loadContent();
8888
});
8989

90+
effect(async () => {
91+
const dynamicComponent = this.block()?.dynamicComponent();
92+
93+
if (dynamicComponent) {
94+
await dynamicComponent.ready();
95+
this.myOverviewBlock = dynamicComponent.instance;
96+
}
97+
});
98+
9099
this.logView = CoreTime.once(async () => {
91100
await CorePromiseUtils.ignoreErrors(CoreCourses.logView('my'));
92101

@@ -138,8 +147,6 @@ export default class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirect
138147

139148
await CoreWait.nextTicks(2);
140149

141-
this.myOverviewBlock = this.block?.dynamicComponent?.instance as AddonBlockMyOverviewComponent;
142-
143150
if (!this.loadedBlock && !supportsMyParam) {
144151
// In old sites, display the block even if not found in Dashboard.
145152
// This is because the "My courses" page doesn't exist in the site so it can't be configured.

0 commit comments

Comments
 (0)