Skip to content

Commit 4a81ddb

Browse files
refactor: convert <UnitButton> and <UnitIcon> to TSX (#2649)
1 parent 2215fc5 commit 4a81ddb

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
import PropTypes from 'prop-types';
1+
import { type FC } from 'react';
22
import { useSelector } from 'react-redux';
33
import { Button } from '@openedx/paragon';
44
import { Link } from 'react-router-dom';
55

6+
import { DeprecatedReduxState } from '@src/store';
7+
import { getCourseId, getSequenceId } from '@src/course-unit/data/selectors';
68
import UnitIcon from './UnitIcon';
7-
import { getCourseId, getSequenceId } from '../../data/selectors';
89

9-
const UnitButton = ({
10+
interface Props {
11+
unitId: string;
12+
className?: string;
13+
showTitle?: boolean;
14+
isActive?: boolean;
15+
}
16+
17+
const UnitButton: FC<Props> = ({
1018
unitId,
1119
className,
12-
showTitle,
1320
isActive, // passed from parent (SequenceNavigationTabs)
21+
showTitle = false,
1422
}) => {
1523
const courseId = useSelector(getCourseId);
1624
const sequenceId = useSelector(getSequenceId);
1725

18-
const unit = useSelector((state) => state.models.units[unitId]);
26+
const unit = useSelector((state: DeprecatedReduxState) => state.models.units[unitId]);
1927
const { title, contentType } = unit || {};
2028

2129
return (
@@ -33,17 +41,4 @@ const UnitButton = ({
3341
);
3442
};
3543

36-
UnitButton.propTypes = {
37-
className: PropTypes.string,
38-
showTitle: PropTypes.bool,
39-
unitId: PropTypes.string.isRequired,
40-
isActive: PropTypes.bool,
41-
};
42-
43-
UnitButton.defaultProps = {
44-
className: undefined,
45-
showTitle: false,
46-
isActive: false,
47-
};
48-
4944
export default UnitButton;
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import PropTypes from 'prop-types';
1+
import { type FC } from 'react';
22
import { Icon } from '@openedx/paragon';
33
import { BookOpen as BookOpenIcon } from '@openedx/paragon/icons';
44

5-
import { UNIT_TYPE_ICONS_MAP, UNIT_ICON_TYPES } from '../../../generic/block-type-utils/constants';
5+
import { UNIT_TYPE_ICONS_MAP } from '@src/generic/block-type-utils/constants';
66

7-
const UnitIcon = ({ type }) => {
7+
interface Props {
8+
type: keyof typeof UNIT_TYPE_ICONS_MAP;
9+
}
10+
11+
const UnitIcon: FC<Props> = ({ type }) => {
812
const icon = UNIT_TYPE_ICONS_MAP[type] || BookOpenIcon;
913

1014
return <Icon src={icon} screenReaderText={type} />;
1115
};
1216

13-
UnitIcon.propTypes = {
14-
type: PropTypes.oneOf(UNIT_ICON_TYPES).isRequired,
15-
};
16-
1717
export default UnitIcon;

src/generic/block-type-utils/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import {
2121
} from '@openedx/paragon/icons';
2222
import NewsstandIcon from '../NewsstandIcon';
2323

24-
export const UNIT_ICON_TYPES = ['video', 'other', 'vertical', 'problem', 'lock'];
25-
2624
export const COMPONENT_TYPES = {
2725
advanced: 'advanced',
2826
discussion: 'discussion',

0 commit comments

Comments
 (0)