@@ -2,6 +2,7 @@ import { useContext } from 'react';
22import { useNavigate , useParams } from 'react-router-dom' ;
33import { Tab , Tabs } from '@openedx/paragon' ;
44import { SlotContext , useWidgetsForId } from '@openedx/frontend-base' ;
5+ import { useCourseInfo } from '../data/apiHook' ;
56
67export interface TabProps {
78 tab_id : string ,
@@ -28,23 +29,37 @@ const InstructorTabs = () => {
2829 const navigate = useNavigate ( ) ;
2930 const { courseId, tabId } = useParams < { courseId : string , tabId ?: string } > ( ) ;
3031 const { id : slotId } = useContext ( SlotContext ) ;
32+ const { data : courseInfo , isLoading } = useCourseInfo ( courseId ?? '' ) ;
3133 const widgetPropsArray = useWidgetProps ( slotId ) ;
3234
35+ const apiTabs : TabProps [ ] = courseInfo ?. tabs ?? [ ] ;
36+ const allTabs = [ ...apiTabs ] ;
37+
38+ widgetPropsArray . forEach ( slotTab => {
39+ if ( ! apiTabs . find ( apiTab => apiTab . tab_id === slotTab . tab_id ) ) {
40+ allTabs . push ( slotTab ) ;
41+ }
42+ } ) ;
43+
3344 const activeKey = tabId ?? 'course_info' ;
3445 const handleSelect = ( eventKey : string | null ) => {
3546 if ( eventKey && courseId ) {
36- const selectedTab = widgetPropsArray . find ( ( { tab_id } ) => tab_id === eventKey ) ;
47+ const selectedTab = allTabs . find ( ( { tab_id } ) => tab_id === eventKey ) ;
3748 if ( selectedTab ) {
3849 navigate ( `/${ courseId } /${ eventKey } ` ) ;
3950 }
4051 }
4152 } ;
4253
43- if ( widgetPropsArray . length === 0 ) return null ;
54+ if ( isLoading ) {
55+ return < div > Loading tabs...</ div > ;
56+ }
57+
58+ if ( allTabs . length === 0 ) return null ;
4459
4560 return (
4661 < Tabs id = "instructor-tabs" activeKey = { activeKey } onSelect = { handleSelect } >
47- { widgetPropsArray . map ( ( { tab_id, title } ) => (
62+ { allTabs . map ( ( { tab_id, title } ) => (
4863 < Tab key = { tab_id } eventKey = { tab_id } title = { title } />
4964 ) ) }
5065 </ Tabs >
0 commit comments