-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: library home page ("bare bones") (#1076)
- Loading branch information
Showing
23 changed files
with
830 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,80 @@ | ||
// @ts-check | ||
/* eslint-disable react/require-default-props */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { StudioHeader } from '@edx/frontend-component-header'; | ||
import { useToggle } from '@openedx/paragon'; | ||
import { generatePath, useHref } from 'react-router-dom'; | ||
|
||
import SearchModal from '../search-modal/SearchModal'; | ||
import { SearchModal } from '../search-modal'; | ||
import { getContentMenuItems, getSettingMenuItems, getToolsMenuItems } from './utils'; | ||
import messages from './messages'; | ||
|
||
interface HeaderProps { | ||
contextId?: string, | ||
number?: string, | ||
org?: string, | ||
title?: string, | ||
isHiddenMainMenu?: boolean, | ||
isLibrary?: boolean, | ||
} | ||
|
||
const Header = ({ | ||
courseId, | ||
courseOrg, | ||
courseNumber, | ||
courseTitle, | ||
isHiddenMainMenu, | ||
}) => { | ||
contextId = '', | ||
org = '', | ||
number = '', | ||
title = '', | ||
isHiddenMainMenu = false, | ||
isLibrary = false, | ||
}: HeaderProps) => { | ||
const intl = useIntl(); | ||
const libraryHref = useHref('/library/:libraryId'); | ||
|
||
const [isShowSearchModalOpen, openSearchModal, closeSearchModal] = useToggle(false); | ||
|
||
const studioBaseUrl = getConfig().STUDIO_BASE_URL; | ||
const meiliSearchEnabled = [true, 'true'].includes(getConfig().MEILISEARCH_ENABLED); | ||
const mainMenuDropdowns = [ | ||
const mainMenuDropdowns = !isLibrary ? [ | ||
{ | ||
id: `${intl.formatMessage(messages['header.links.content'])}-dropdown-menu`, | ||
buttonTitle: intl.formatMessage(messages['header.links.content']), | ||
items: getContentMenuItems({ studioBaseUrl, courseId, intl }), | ||
items: getContentMenuItems({ studioBaseUrl, courseId: contextId, intl }), | ||
}, | ||
{ | ||
id: `${intl.formatMessage(messages['header.links.settings'])}-dropdown-menu`, | ||
buttonTitle: intl.formatMessage(messages['header.links.settings']), | ||
items: getSettingMenuItems({ studioBaseUrl, courseId, intl }), | ||
items: getSettingMenuItems({ studioBaseUrl, courseId: contextId, intl }), | ||
}, | ||
{ | ||
id: `${intl.formatMessage(messages['header.links.tools'])}-dropdown-menu`, | ||
buttonTitle: intl.formatMessage(messages['header.links.tools']), | ||
items: getToolsMenuItems({ studioBaseUrl, courseId, intl }), | ||
items: getToolsMenuItems({ studioBaseUrl, courseId: contextId, intl }), | ||
}, | ||
]; | ||
const outlineLink = `${studioBaseUrl}/course/${courseId}`; | ||
] : []; | ||
const outlineLink = !isLibrary | ||
? `${studioBaseUrl}/course/${contextId}` | ||
: generatePath(libraryHref, { libraryId: contextId }); | ||
|
||
return ( | ||
<> | ||
<StudioHeader | ||
org={courseOrg} | ||
number={courseNumber} | ||
title={courseTitle} | ||
org={org} | ||
number={number} | ||
title={title} | ||
isHiddenMainMenu={isHiddenMainMenu} | ||
mainMenuDropdowns={mainMenuDropdowns} | ||
outlineLink={outlineLink} | ||
searchButtonAction={meiliSearchEnabled && openSearchModal} | ||
searchButtonAction={meiliSearchEnabled ? openSearchModal : undefined} | ||
/> | ||
{ meiliSearchEnabled && ( | ||
<SearchModal | ||
isOpen={isShowSearchModalOpen} | ||
courseId={courseId} | ||
courseId={isLibrary ? undefined : contextId} | ||
onClose={closeSearchModal} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
Header.propTypes = { | ||
courseId: PropTypes.string, | ||
courseNumber: PropTypes.string, | ||
courseOrg: PropTypes.string, | ||
courseTitle: PropTypes.string, | ||
isHiddenMainMenu: PropTypes.bool, | ||
}; | ||
|
||
Header.defaultProps = { | ||
courseId: '', | ||
courseNumber: '', | ||
courseOrg: '', | ||
courseTitle: '', | ||
isHiddenMainMenu: false, | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { Container } from '@openedx/paragon'; | ||
|
||
import Header from '../header'; | ||
import SubHeader from '../generic/sub-header/SubHeader'; | ||
|
||
import messages from './messages'; | ||
|
||
/* istanbul ignore next This is only a placeholder component */ | ||
const CreateLibrary = () => ( | ||
<> | ||
<Header isHiddenMainMenu /> | ||
<Container size="xl" className="p-4 mt-3"> | ||
<SubHeader | ||
title={<FormattedMessage {...messages.createLibrary} />} | ||
/> | ||
<div className="d-flex my-6 justify-content-center"> | ||
<FormattedMessage | ||
{...messages.createLibraryTempPlaceholder} | ||
/> | ||
</div> | ||
</Container> | ||
</> | ||
); | ||
|
||
export default CreateLibrary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { | ||
Button, Stack, | ||
} from '@openedx/paragon'; | ||
import { Add } from '@openedx/paragon/icons'; | ||
|
||
import messages from './messages'; | ||
|
||
export const NoComponents = () => ( | ||
<Stack direction="horizontal" gap={3} className="mt-6 justify-content-center"> | ||
<FormattedMessage {...messages.noComponents} /> | ||
<Button iconBefore={Add}> | ||
<FormattedMessage {...messages.addComponent} /> | ||
</Button> | ||
</Stack> | ||
); | ||
|
||
export const NoSearchResults = () => ( | ||
<div className="d-flex mt-6 justify-content-center"> | ||
<FormattedMessage {...messages.noSearchResults} /> | ||
</div> | ||
); |
Oops, something went wrong.