-
Notifications
You must be signed in to change notification settings - Fork 8
Introduce courseNavigationBar on header slot #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1908a3c
1bfea65
ae758b6
0a7347e
3999521
d2a328a
0877423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { useState } from 'react'; | ||
| import { useLocation } from 'react-router-dom'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { Slot, useIntl } from '../../../runtime'; | ||
| import { CourseTab, getCourseHomeCourseMetadata } from './data/service'; | ||
| import './course-tabs-navigation.scss'; | ||
| import { Nav, Navbar, Skeleton } from '@openedx/paragon'; | ||
| import messages from './messages'; | ||
|
|
||
| const extractCourseId = (pathname: string): string => { | ||
| const courseRegex = /\/courses?\/([^/]+)/; | ||
| const courseMatch = courseRegex.exec(pathname); | ||
| return courseMatch ? courseMatch[1] : ''; | ||
| }; | ||
|
|
||
| const CourseTabsNavigation = () => { | ||
| const location = useLocation(); | ||
| const [currentTab, setCurrentTab] = useState<string | null>(null); | ||
| const intl = useIntl(); | ||
|
|
||
| const courseId = extractCourseId(location.pathname); | ||
|
|
||
| const { data = { tabs: [], isMasquerading: false }, isLoading } = useQuery({ | ||
| queryKey: ['org.openedx.frontend.app.header.course-meta', courseId], | ||
| queryFn: () => getCourseHomeCourseMetadata(courseId), | ||
| retry: 2, | ||
| enabled: !!courseId, | ||
| }); | ||
|
|
||
| const { tabs } = data; | ||
|
|
||
| if (isLoading) { | ||
| return <Skeleton className="lead" />; | ||
| } | ||
|
|
||
| if (!courseId || !tabs || tabs.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Navbar className="course-tabs-navigation pb-0" ariaLabel={intl.formatMessage(messages.courseMaterial)}> | ||
| <Nav | ||
| variant="tabs" | ||
| activeKey={currentTab} | ||
| > | ||
| { | ||
| tabs.map((tab: CourseTab) => ( | ||
| <Nav.Item key={tab.tabId}> | ||
| <Nav.Link | ||
| href={tab.url} | ||
| active={tab.tabId === currentTab} | ||
| onClick={() => setCurrentTab(tab.tabId)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place On the other hand, shouldn't we have a way to |
||
| > | ||
| {tab.title} | ||
| </Nav.Link> | ||
| </Nav.Item> | ||
| )) | ||
| } | ||
| <Slot id="org.openedx.frontend.slot.header.courseNavigationBar.extraContent.v1" /> | ||
| </Nav> | ||
| </Navbar> | ||
| ); | ||
| }; | ||
|
|
||
| export default CourseTabsNavigation; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const activeRolesForCourseNavigationBar = [ | ||
| 'org.openedx.frontend.role.learning', | ||
| 'org.openedx.frontend.role.discussions', | ||
| 'org.openedx.frontend.role.instructor', | ||
| ]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .course-tabs-navigation { | ||
| border-bottom: 2px solid var(--pgn-color-nav-tabs-base-border-base); | ||
|
|
||
| .nav-tabs { | ||
| border-bottom: none; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { getSiteConfig, getAuthenticatedHttpClient, camelCaseObject } from '../../../../runtime'; | ||
|
|
||
| export const getCourseMetadataApiUrl = (courseId: string) => `${getSiteConfig().lmsBaseUrl}/api/course_home/course_metadata/${courseId}`; | ||
|
|
||
| export interface CourseTab { | ||
| tabId: string, | ||
| title: string, | ||
| url: string, | ||
| } | ||
| export interface CourseHomeCourseMetadata { | ||
| tabs: CourseTab[], | ||
| isMasquerading: boolean, | ||
| } | ||
|
|
||
| function normalizeCourseHomeCourseMetadata(metadata: CourseHomeCourseMetadata): CourseHomeCourseMetadata { | ||
| const data = camelCaseObject(metadata); | ||
| return { | ||
| ...data, | ||
| tabs: (data.tabs || []).map((tab: CourseTab) => ({ | ||
| tabId: tab.tabId === 'courseware' ? 'outline' : tab.tabId, | ||
| title: tab.title, | ||
| url: tab.url, | ||
| })), | ||
| isMasquerading: data.originalUserIsStaff && !data.isStaff, | ||
| }; | ||
| } | ||
|
|
||
| export async function getCourseHomeCourseMetadata(courseId: string): Promise<CourseHomeCourseMetadata> { | ||
| const url = getCourseMetadataApiUrl(courseId); | ||
| const { data } = await getAuthenticatedHttpClient().get(url); | ||
|
|
||
| return normalizeCourseHomeCourseMetadata(data); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { defineMessages } from '../../../runtime'; | ||
|
|
||
| const messages = defineMessages({ | ||
| courseMaterial: { | ||
diana-villalvazo-wgu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| id: 'org.openedx.frontend.slot.header.courseNavigationBar.tabs.label', | ||
| defaultMessage: 'Course Navigation Bar', | ||
| description: 'The accessible label for course tabs navigation', | ||
| }, | ||
| }); | ||
|
|
||
| export default messages; | ||
Uh oh!
There was an error while loading. Please reload this page.