forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitButton.tsx
More file actions
44 lines (38 loc) · 1.18 KB
/
UnitButton.tsx
File metadata and controls
44 lines (38 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { type FC } from 'react';
import { useSelector } from 'react-redux';
import { Button } from '@openedx/paragon';
import { Link } from 'react-router-dom';
import { DeprecatedReduxState } from '@src/store';
import { getCourseId, getSequenceId } from '@src/course-unit/data/selectors';
import UnitIcon from './UnitIcon';
interface Props {
unitId: string;
className?: string;
showTitle?: boolean;
isActive?: boolean;
}
const UnitButton: FC<Props> = ({
unitId,
className,
isActive, // passed from parent (SequenceNavigationTabs)
showTitle = false,
}) => {
const courseId = useSelector(getCourseId);
const sequenceId = useSelector(getSequenceId);
const unit = useSelector((state: DeprecatedReduxState) => state.models.units[unitId]);
const { title, contentType } = unit || {};
return (
<Button
className={className}
variant={isActive ? 'primary' : 'outline-primary'}
as={Link}
title={title}
to={`/course/${courseId}/container/${unitId}/${sequenceId}/`}
data-testid="course-unit-btn"
>
<UnitIcon type={contentType} />
{showTitle && <span className="unit-title">{title}</span>}
</Button>
);
};
export default UnitButton;