Skip to content

Commit 5681171

Browse files
chore: addressing feedback
1 parent eacf71f commit 5681171

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

shell/header/course-navigation-bar/CourseTabsNavigation.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { useNavigate, useLocation } from 'react-router-dom';
2+
import classNames from 'classnames';
13
import { useQuery } from '@tanstack/react-query';
4+
import { Tab, Tabs } from '@openedx/paragon';
25
import { Slot, useIntl } from '../../../runtime';
3-
import classNames from 'classnames';
46
import { getCourseHomeCourseMetadata } from './data/service';
5-
import { Tab, Tabs } from '@openedx/paragon';
67
import messages from './messages';
7-
import { useNavigate, useLocation } from 'react-router-dom';
88
import './course-tabs-navigation.scss';
99

1010
interface CourseMetaData {
@@ -16,23 +16,24 @@ interface CourseMetaData {
1616
isMasquerading: boolean,
1717
}
1818

19+
const extractCourseId = (pathname: string): string => {
20+
const courseRegex = /\/courses?\/([^/]+)/;
21+
const courseMatch = courseRegex.exec(pathname);
22+
return courseMatch ? courseMatch[1] : '';
23+
};
24+
1925
const CourseTabsNavigation = () => {
2026
const location = useLocation();
2127
const intl = useIntl();
2228
const navigate = useNavigate();
2329

24-
const extractCourseId = (pathname: string): string => {
25-
const courseRegex = /\/courses?\/([^/]+)/;
26-
const courseMatch = courseRegex.exec(pathname);
27-
return courseMatch ? courseMatch[1] : '';
28-
};
29-
3030
const courseId = extractCourseId(location.pathname);
3131

3232
const { data } = useQuery({
3333
queryKey: ['org.openedx.frontend.app.header.course-meta', courseId],
3434
queryFn: () => getCourseHomeCourseMetadata(courseId),
3535
retry: 2,
36+
enabled: !!courseId,
3637
});
3738

3839
if (!courseId) {
@@ -41,7 +42,7 @@ const CourseTabsNavigation = () => {
4142

4243
const { tabs = [] }: CourseMetaData = data ?? {};
4344

44-
const handleSelectedTab = (eventKey) => {
45+
const handleSelectedTab = (eventKey: string | null) => {
4546
const selectedUrl = tabs.find(tab => tab.slug === eventKey)?.url ?? '/';
4647

4748
try {

shell/header/course-navigation-bar/data/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function normalizeCourseHomeCourseMetadata(metadata) {
66
const data = camelCaseObject(metadata);
77
return {
88
...data,
9-
tabs: data.tabs.map(tab => ({
9+
tabs: (data.tabs || []).map(tab => ({
1010
slug: tab.tabId === 'courseware' ? 'outline' : tab.tabId,
1111
title: tab.title,
1212
url: tab.url,

0 commit comments

Comments
 (0)