forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.jsx
More file actions
74 lines (68 loc) · 1.83 KB
/
index.jsx
File metadata and controls
74 lines (68 loc) · 1.83 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
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { Icon, IconButton, Truncate } from '@openedx/paragon';
import { EditOutline } from '@openedx/paragon/icons';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { selectors } from '../../../../data/redux';
import { localTitleHooks } from './hooks';
import messages from './messages';
import EditableHeader from './EditableHeader';
const TitleHeader = ({
isInitialized,
// injected
intl,
}) => {
if (!isInitialized) { return intl.formatMessage(messages.loading); }
// eslint-disable-next-line react-hooks/rules-of-hooks
const dispatch = useDispatch();
// eslint-disable-next-line react-hooks/rules-of-hooks
const title = useSelector(selectors.app.displayTitle);
const {
inputRef,
isEditing,
handleChange,
handleKeyDown,
localTitle,
startEditing,
cancelEdit,
updateTitle,
} = localTitleHooks({ dispatch });
if (isEditing) {
return (
<EditableHeader
{...{
inputRef,
handleChange,
handleKeyDown,
localTitle,
updateTitle,
cancelEdit,
}}
/>
);
}
return (
<div className="d-flex flex-row align-items-center mt-1">
<Truncate.Deprecated>
{title}
</Truncate.Deprecated>
<IconButton
alt={intl.formatMessage(messages.editTitleLabel)}
iconAs={Icon}
className="mx-2"
onClick={startEditing}
size="sm"
src={EditOutline}
/>
</div>
);
};
TitleHeader.defaultProps = {};
TitleHeader.propTypes = {
isInitialized: PropTypes.bool.isRequired,
// injected
intl: intlShape.isRequired,
};
export const TitleHeaderInternal = TitleHeader; // For testing only
export default injectIntl(TitleHeader);