Skip to content

Commit cfa0ccb

Browse files
committed
MOBILE-4860 course: Handle current view in getAndOpenCourse
1 parent d91092a commit cfa0ccb

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

src/addons/mod/subsection/services/handlers/index-link.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { CoreContentLinksAction } from '@features/contentlinks/services/contentl
1818
import { CoreCourse } from '@features/course/services/course';
1919
import { CoreLoadings } from '@services/overlays/loadings';
2020
import { makeSingleton } from '@singletons';
21-
import { CoreSites } from '@services/sites';
2221
import { CoreCourseHelper } from '@features/course/services/course-helper';
2322
import { CoreAlerts } from '@services/overlays/alerts';
2423
import { ADDON_MOD_SUBSECTION_COMPONENT, ADDON_MOD_SUBSECTION_MODNAME } from '../../constants';
@@ -48,14 +47,7 @@ export class AddonModSubsectionIndexLinkHandlerService extends CoreContentLinksM
4847
sectionId,
4948
};
5049

51-
if (
52-
(!siteId || siteId === CoreSites.getCurrentSiteId()) &&
53-
CoreCourse.currentViewIsCourse(courseId)
54-
) {
55-
CoreCourse.selectCourseTab('', pageParams);
56-
} else {
57-
await CoreCourseHelper.getAndOpenCourse(courseId, pageParams, siteId);
58-
}
50+
await CoreCourseHelper.getAndOpenCourse(courseId, pageParams, siteId);
5951
}
6052

6153
/**

src/core/features/course/components/course-format/course-format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
180180
let section: CoreCourseSection | undefined;
181181

182182
if (data.sectionId !== undefined && this.sections) {
183-
section = this.sections.find((section) => section.id == data.sectionId);
183+
section = this.sections.find((section) => section.id === data.sectionId);
184184
} else if (data.sectionNumber !== undefined && this.sections) {
185-
section = this.sections.find((section) => section.section == data.sectionNumber);
185+
section = this.sections.find((section) => section.section === data.sectionNumber);
186186
}
187187

188188
if (section) {

src/core/features/course/pages/index/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class CoreCourseIndexPage implements OnInit, OnDestroy {
8787
// Select course contents.
8888
this.tabsComponent?.selectByIndex(0);
8989
} else if (this.tabs) {
90-
const index = this.tabs.findIndex((tab) => tab.name == data.name);
90+
const index = this.tabs.findIndex((tab) => tab.name === data.name);
9191

9292
if (index >= 0) {
9393
this.tabsComponent?.selectByIndex(index);

src/core/features/course/services/course-helper.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,15 @@ export class CoreCourseHelperProvider {
987987
* @returns Promise resolved when done.
988988
*/
989989
async getAndOpenCourse(courseId: number, params?: Params, siteId?: string): Promise<void> {
990+
siteId = siteId ?? CoreSites.getCurrentSiteId();
991+
992+
// Do not navigate if the course is already being displayed.
993+
if (siteId === CoreSites.getCurrentSiteId() && CoreCourse.currentViewIsCourse(courseId)) {
994+
CoreCourse.selectCourseTab(params?.selectedTab, params);
995+
996+
return;
997+
}
998+
990999
const modal = await CoreLoadings.show();
9911000

9921001
let course: CoreCourseAnyCourseData | { id: number };
@@ -1473,7 +1482,7 @@ export class CoreCourseHelperProvider {
14731482
modNavOptions: options.modNavOptions,
14741483
};
14751484

1476-
if (courseId == site.getSiteHomeId()) {
1485+
if (courseId === site.getSiteHomeId()) {
14771486
// Check if site home is available.
14781487
const isAvailable = await CoreSiteHome.isAvailable();
14791488

src/core/features/grades/services/grades-helper.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,21 +495,13 @@ export class CoreGradesHelperProvider {
495495
} catch {
496496
try {
497497
// Cannot get grade items or there's no need to.
498-
if (userId && userId != currentUserId) {
498+
if (userId && userId !== currentUserId) {
499499
// View another user grades. Open the grades page directly.
500500
await CorePromiseUtils.ignoreErrors(
501501
CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId }),
502502
);
503503
}
504504

505-
// View own grades. Check if we already are in the course index page.
506-
if (CoreCourse.currentViewIsCourse(courseId)) {
507-
// Current view is this course, just select the grades tab.
508-
CoreCourse.selectCourseTab(CORE_GRADES_COURSE_OPTION_NAME);
509-
510-
return;
511-
}
512-
513505
// Open the course with the grades tab selected.
514506
await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: CORE_GRADES_COURSE_OPTION_NAME }, siteId);
515507
} catch {

0 commit comments

Comments
 (0)