forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequenceNavigation.jsx
More file actions
124 lines (110 loc) · 3.49 KB
/
SequenceNavigation.jsx
File metadata and controls
124 lines (110 loc) · 3.49 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { Link } from 'react-router-dom';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {
injectIntl, intlShape, isRtl, getLocale,
} from '@edx/frontend-platform/i18n';
import { Button, useWindowSize, breakpoints } from '@openedx/paragon';
import {
ChevronLeft as ChevronLeftIcon,
ChevronRight as ChevronRightIcon,
} from '@openedx/paragon/icons';
import { useModel } from '../../../generic/model-store';
import { RequestStatus } from '../../../data/constants';
import { getSequenceStatus } from '../../data/selectors';
import { useSequenceNavigationMetadata } from '../hooks';
import messages from '../messages';
import SequenceNavigationTabs from './SequenceNavigationTabs';
const SequenceNavigation = ({
intl,
courseId,
unitId,
sequenceId,
className,
handleCreateNewCourseXBlock,
showPasteUnit,
}) => {
const sequenceStatus = useSelector(getSequenceStatus);
const {
isFirstUnit, isLastUnit, nextLink, previousLink,
} = useSequenceNavigationMetadata(courseId, sequenceId, unitId);
const sequence = useModel('sequences', sequenceId);
const shouldDisplayNotificationTriggerInSequence = useWindowSize().width < breakpoints.small.minWidth;
const renderUnitButtons = () => {
if (sequence.unitIds.length === 0 || unitId === null) {
return (
<div style={{ flexBasis: '100%', minWidth: 0, borderBottom: 'solid 1px #EAEAEA' }} />
);
}
return (
<SequenceNavigationTabs
unitIds={sequence?.unitIds || []}
unitId={unitId}
handleCreateNewCourseXBlock={handleCreateNewCourseXBlock}
showPasteUnit={showPasteUnit}
/>
);
};
const renderPreviousButton = () => {
const buttonText = intl.formatMessage(messages.prevBtnText);
const prevArrow = isRtl(getLocale()) ? ChevronRightIcon : ChevronLeftIcon;
if (!isFirstUnit) {
return (
<Button
className="sequence-navigation-prev-btn"
variant="outline-primary"
iconBefore={prevArrow}
as={Link}
to={previousLink}
>
{shouldDisplayNotificationTriggerInSequence ? null : buttonText}
</Button>
);
}
return null;
};
const renderNextButton = () => {
const buttonText = intl.formatMessage(messages.nextBtnText);
const nextArrow = isRtl(getLocale()) ? ChevronLeftIcon : ChevronRightIcon;
if (!isLastUnit) {
return (
<Button
className="sequence-navigation-next-btn"
variant="outline-primary"
iconAfter={nextArrow}
as={Link}
to={nextLink}
>
{shouldDisplayNotificationTriggerInSequence ? null : buttonText}
</Button>
);
}
return null;
};
return sequenceStatus === RequestStatus.SUCCESSFUL && (
<nav
className={classNames('sequence-navigation d-flex', className)}
style={{ width: shouldDisplayNotificationTriggerInSequence ? '90%' : null }}
>
{renderPreviousButton()}
{renderUnitButtons()}
{renderNextButton()}
</nav>
);
};
SequenceNavigation.propTypes = {
intl: intlShape.isRequired,
courseId: PropTypes.string.isRequired,
unitId: PropTypes.string,
className: PropTypes.string,
sequenceId: PropTypes.string,
handleCreateNewCourseXBlock: PropTypes.func.isRequired,
showPasteUnit: PropTypes.bool.isRequired,
};
SequenceNavigation.defaultProps = {
sequenceId: null,
unitId: null,
className: undefined,
};
export default injectIntl(SequenceNavigation);