Skip to content

Commit

Permalink
refactor: migrate Header to ts and fix some types
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Jul 3, 2024
1 parent 6acee0a commit 7515975
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
44 changes: 17 additions & 27 deletions src/header/Header.jsx → src/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @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';
Expand All @@ -10,14 +9,23 @@ import { SearchModal } from '../search-modal';
import { getContentMenuItems, getSettingMenuItems, getToolsMenuItems } from './utils';
import messages from './messages';

interface HeaderProps {
contentId?: string,
number?: string,
org?: string,
title?: string,
isHiddenMainMenu?: boolean,
isLibrary?: boolean,
}

const Header = ({
contentId,
org,
number,
title,
isHiddenMainMenu,
isLibrary,
}) => {
contentId = '',
org = '',
number = '',
title = '',
isHiddenMainMenu = false,
isLibrary = false,
}: HeaderProps) => {
const intl = useIntl();

const [isShowSearchModalOpen, openSearchModal, closeSearchModal] = useToggle(false);
Expand Down Expand Up @@ -65,22 +73,4 @@ const Header = ({
);
};

Header.propTypes = {
contentId: PropTypes.string,
number: PropTypes.string,
org: PropTypes.string,
title: PropTypes.string,
isHiddenMainMenu: PropTypes.bool,
isLibrary: PropTypes.bool,
};

Header.defaultProps = {
contentId: '',
number: '',
org: '',
title: '',
isHiddenMainMenu: false,
isLibrary: false,
};

export default Header;
3 changes: 2 additions & 1 deletion src/search-modal/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { ModalDialog } from '@openedx/paragon';
import messages from './messages';
import SearchUI from './SearchUI';

const SearchModal: React.FC<{ courseId: string, isOpen: boolean, onClose: () => void }> = ({ courseId, ...props }) => {
// eslint-disable-next-line react/require-default-props
const SearchModal: React.FC<{ courseId?: string, isOpen: boolean, onClose: () => void }> = ({ courseId, ...props }) => {
const intl = useIntl();
const title = intl.formatMessage(messages.title);

Expand Down
2 changes: 1 addition & 1 deletion src/search-modal/SearchUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Stats from './Stats';
import { SearchContextProvider } from './manager/SearchManager';
import messages from './messages';

const SearchUI: React.FC<{ courseId: string, closeSearchModal?: () => void }> = (props) => {
const SearchUI: React.FC<{ courseId?: string, closeSearchModal?: () => void }> = (props) => {
const hasCourseId = Boolean(props.courseId);
const [searchThisCourseEnabled, setSearchThisCourse] = React.useState(hasCourseId);
const switchToThisCourse = React.useCallback(() => setSearchThisCourse(true), []);
Expand Down

0 comments on commit 7515975

Please sign in to comment.