1+ import { useNavigate , useLocation } from 'react-router-dom' ;
2+ import classNames from 'classnames' ;
13import { useQuery } from '@tanstack/react-query' ;
4+ import { Tab , Tabs } from '@openedx/paragon' ;
25import { Slot , useIntl } from '../../../runtime' ;
3- import classNames from 'classnames' ;
46import { getCourseHomeCourseMetadata } from './data/service' ;
5- import { Tab , Tabs } from '@openedx/paragon' ;
67import messages from './messages' ;
7- import { useNavigate , useLocation } from 'react-router-dom' ;
88import './course-tabs-navigation.scss' ;
99
1010interface CourseMetaData {
@@ -16,23 +16,24 @@ interface CourseMetaData {
1616 isMasquerading : boolean ,
1717}
1818
19+ const extractCourseId = ( pathname : string ) : string => {
20+ const courseRegex = / \/ c o u r s e s ? \/ ( [ ^ / ] + ) / ;
21+ const courseMatch = courseRegex . exec ( pathname ) ;
22+ return courseMatch ? courseMatch [ 1 ] : '' ;
23+ } ;
24+
1925const CourseTabsNavigation = ( ) => {
2026 const location = useLocation ( ) ;
2127 const intl = useIntl ( ) ;
2228 const navigate = useNavigate ( ) ;
2329
24- const extractCourseId = ( pathname : string ) : string => {
25- const courseRegex = / \/ c o u r s e s ? \/ ( [ ^ / ] + ) / ;
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 {
0 commit comments