Skip to content

Commit 033639f

Browse files
committed
MOBILE-4842 chore: Review most of viewChild to reduce errors
1 parent 5a05e1f commit 033639f

File tree

40 files changed

+68
-68
lines changed

40 files changed

+68
-68
lines changed

src/addons/messages/pages/discussion/discussion.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import { CoreSharedModule } from '@/core/shared.module';
7070
})
7171
export default class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterViewInit {
7272

73-
readonly content = viewChild(IonContent);
73+
readonly content = viewChild.required(IonContent);
7474
readonly infinite = viewChild(CoreInfiniteLoadingComponent);
7575

7676
protected fetching = false;
@@ -174,7 +174,7 @@ export default class AddonMessagesDiscussionPage implements OnInit, OnDestroy, A
174174
* @inheritdoc
175175
*/
176176
async ngAfterViewInit(): Promise<void> {
177-
this.scrollElement = await this.content()?.getScrollElement();
177+
this.scrollElement = await this.content().getScrollElement();
178178
}
179179

180180
/**
@@ -878,7 +878,7 @@ export default class AddonMessagesDiscussionPage implements OnInit, OnDestroy, A
878878
const newScrollHeight = (this.scrollElement?.scrollHeight || 0);
879879
const scrollTo = newScrollHeight - oldScrollBottom + infiniteHeight;
880880

881-
this.content()?.scrollToPoint(0, scrollTo, 0);
881+
this.content().scrollToPoint(0, scrollTo, 0);
882882
}, 30);
883883
}, 30);
884884
}

src/addons/messages/pages/group-conversations/group-conversations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const enum AddonMessagesGroupConversationOptionNames {
7373
export default class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
7474

7575
readonly splitView = viewChild.required(CoreSplitViewComponent);
76-
readonly content = viewChild(IonContent);
76+
readonly content = viewChild.required(IonContent);
7777
readonly accordionGroup = viewChild.required<IonAccordionGroup>('accordionGroup');
7878

7979
loaded = false;
@@ -189,7 +189,7 @@ export default class AddonMessagesGroupConversationsPage implements OnInit, OnDe
189189

190190
if (isNewer) {
191191
// The last message is newer than the previous one, scroll to top to keep viewing the conversation.
192-
this.content()?.scrollToTop();
192+
this.content().scrollToTop();
193193
}
194194
}
195195
},

src/addons/mod/assign/pages/index/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class AddonModAssignIndexPage extends CoreCourseModuleMainActivit
3535

3636
private action?: string;
3737

38-
readonly activityComponent = viewChild(AddonModAssignIndexComponent);
38+
readonly activityComponent = viewChild.required(AddonModAssignIndexComponent);
3939

4040
constructor() {
4141
super();
@@ -49,8 +49,8 @@ export default class AddonModAssignIndexPage extends CoreCourseModuleMainActivit
4949
async ngAfterViewInit(): Promise<void> {
5050
switch (this.action) {
5151
case 'editsubmission':
52-
await CoreWait.waitFor(() => !!this.activityComponent()?.submissionComponent(), { timeout: 5000 });
53-
await this.activityComponent()?.submissionComponent()?.goToEdit();
52+
await CoreWait.waitFor(() => !!this.activityComponent().submissionComponent(), { timeout: 5000 });
53+
await this.activityComponent().submissionComponent()?.goToEdit();
5454

5555
break;
5656
}

src/addons/mod/assign/submission/comments/component/comments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { ADDON_MOD_ASSIGN_COMMENTS_AREA, ADDON_MOD_ASSIGN_COMMENTS_COMPONENT_NAM
3333
})
3434
export class AddonModAssignSubmissionCommentsComponent extends AddonModAssignSubmissionPluginBaseComponent {
3535

36-
readonly commentsComponent = viewChild.required(CoreCommentsCommentsComponent);
36+
readonly commentsComponent = viewChild(CoreCommentsCommentsComponent);
3737

3838
commentsEnabled: boolean;
3939

src/addons/mod/bigbluebuttonbn/pages/index/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ import { CoreSharedModule } from '@/core/shared.module';
3030
})
3131
export default class AddonModBBBIndexPage extends CoreCourseModuleMainActivityPage<AddonModBBBIndexComponent> {
3232

33-
readonly activityComponent = viewChild(AddonModBBBIndexComponent);
33+
readonly activityComponent = viewChild.required(AddonModBBBIndexComponent);
3434

3535
}

src/addons/mod/book/pages/index/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ import { CoreSharedModule } from '@/core/shared.module';
3030
})
3131
export default class AddonModBookIndexPage extends CoreCourseModuleMainActivityPage<AddonModBookIndexComponent> {
3232

33-
readonly activityComponent = viewChild(AddonModBookIndexComponent);
33+
readonly activityComponent = viewChild.required(AddonModBookIndexComponent);
3434

3535
}

src/addons/mod/chat/pages/chat/chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave
4949

5050
protected static readonly POLL_INTERVAL = 4000;
5151

52-
readonly content = viewChild(IonContent);
52+
readonly content = viewChild.required(IonContent);
5353
readonly sendMessageForm = viewChild(CoreSendMessageFormComponent);
5454

5555
loaded = false;
@@ -360,7 +360,7 @@ export default class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave
360360
// Need a timeout to leave time to the view to be rendered.
361361
await CoreWait.nextTick();
362362
if (!this.viewDestroyed) {
363-
this.content()?.scrollToBottom();
363+
this.content().scrollToBottom();
364364
}
365365
}
366366

src/addons/mod/chat/pages/index/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ import { CoreSharedModule } from '@/core/shared.module';
3030
})
3131
export default class AddonModChatIndexPage extends CoreCourseModuleMainActivityPage<AddonModChatIndexComponent> {
3232

33-
readonly activityComponent = viewChild(AddonModChatIndexComponent);
33+
readonly activityComponent = viewChild.required(AddonModChatIndexComponent);
3434

3535
}

src/addons/mod/choice/pages/index/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ import { CoreSharedModule } from '@/core/shared.module';
3030
})
3131
export default class AddonModChoiceIndexPage extends CoreCourseModuleMainActivityPage<AddonModChoiceIndexComponent> {
3232

33-
readonly activityComponent = viewChild(AddonModChoiceIndexComponent);
33+
readonly activityComponent = viewChild.required(AddonModChoiceIndexComponent);
3434

3535
}

src/addons/mod/data/pages/edit/edit.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ import { CoreSharedModule } from '@/core/shared.module';
6464
})
6565
export default class AddonModDataEditPage implements OnInit {
6666

67-
readonly content = viewChild(IonContent);
68-
readonly formElement = viewChild.required<ElementRef>('editFormEl');
67+
readonly content = viewChild.required(IonContent);
68+
readonly formElement = viewChild<ElementRef>('editFormEl');
6969

7070
protected entryId?: number;
7171
protected fieldsArray: AddonModDataField[] = [];
@@ -552,9 +552,9 @@ export default class AddonModDataEditPage implements OnInit {
552552
* Scroll to first error or to the top if not found.
553553
*/
554554
protected async scrollToFirstError(): Promise<void> {
555-
const scrolled = await CoreDom.scrollToElement(this.formElement().nativeElement, '.addon-data-error');
555+
const scrolled = await CoreDom.scrollToElement(this.formElement()?.nativeElement, '.addon-data-error');
556556
if (!scrolled) {
557-
this.content()?.scrollToTop();
557+
this.content().scrollToTop();
558558
}
559559
}
560560

0 commit comments

Comments
 (0)