2021-10-04 21:18:40 +08:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2018-12-13 04:10:27 +08:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
|
2021-05-18 04:25:07 +08:00
|
|
|
import NoteService from '/imports/ui/components/note/service';
|
2021-10-28 01:48:15 +08:00
|
|
|
import Styled from './styles';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { PANELS, ACTIONS } from '../layout/enums';
|
2021-10-28 01:48:15 +08:00
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2018-12-13 04:10:27 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
hideNoteLabel: {
|
|
|
|
id: 'app.note.hideNoteLabel',
|
|
|
|
description: 'Label for hiding note button',
|
|
|
|
},
|
2019-01-10 02:06:23 +08:00
|
|
|
title: {
|
|
|
|
id: 'app.note.title',
|
|
|
|
description: 'Title for the shared notes',
|
|
|
|
},
|
2019-02-24 06:38:58 +08:00
|
|
|
tipLabel: {
|
|
|
|
id: 'app.note.tipLabel',
|
|
|
|
description: 'Label for tip on how to escape iframe',
|
|
|
|
},
|
2018-12-13 04:10:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
2019-03-29 02:47:11 +08:00
|
|
|
isLocked: PropTypes.bool.isRequired,
|
2018-12-13 04:10:27 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2021-10-04 21:18:40 +08:00
|
|
|
isRTL: PropTypes.bool.isRequired,
|
2018-12-13 04:10:27 +08:00
|
|
|
};
|
|
|
|
|
2021-10-04 21:18:40 +08:00
|
|
|
const Note = ({
|
|
|
|
isLocked,
|
|
|
|
intl,
|
|
|
|
isRTL,
|
|
|
|
layoutContextDispatch,
|
|
|
|
isResizing,
|
|
|
|
}) => {
|
|
|
|
const [noteURL, setNoteURL] = useState();
|
2021-10-28 01:48:15 +08:00
|
|
|
const { isChrome } = browserInfo;
|
2018-12-13 04:10:27 +08:00
|
|
|
|
2021-10-04 21:18:40 +08:00
|
|
|
useEffect(() => {
|
|
|
|
NoteService.getNoteId().then((response) => {
|
|
|
|
setNoteURL(NoteService.buildNoteURL(response));
|
|
|
|
});
|
|
|
|
}, [isLocked, isRTL]);
|
2018-12-13 04:10:27 +08:00
|
|
|
|
2021-10-04 21:18:40 +08:00
|
|
|
useEffect(() => () => NoteService.setLastRevs(), []);
|
2019-12-17 05:06:41 +08:00
|
|
|
|
2021-10-04 21:18:40 +08:00
|
|
|
return (
|
2021-10-28 01:48:15 +08:00
|
|
|
<Styled.Note data-test="note" isChrome={isChrome}>
|
|
|
|
<Styled.Header>
|
|
|
|
<Styled.Title data-test="noteTitle">
|
|
|
|
<Styled.HideButton
|
2021-10-04 21:18:40 +08:00
|
|
|
onClick={() => {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.NONE,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
data-test="hideNoteLabel"
|
|
|
|
aria-label={intl.formatMessage(intlMessages.hideNoteLabel)}
|
|
|
|
label={intl.formatMessage(intlMessages.title)}
|
|
|
|
icon={isRTL ? 'right_arrow' : 'left_arrow'}
|
|
|
|
/>
|
2021-10-28 01:48:15 +08:00
|
|
|
</Styled.Title>
|
|
|
|
</Styled.Header>
|
|
|
|
<Styled.IFrame
|
2021-10-04 21:18:40 +08:00
|
|
|
title="etherpad"
|
|
|
|
src={noteURL}
|
|
|
|
aria-describedby="sharedNotesEscapeHint"
|
|
|
|
style={{
|
|
|
|
pointerEvents: isResizing ? 'none' : 'inherit',
|
|
|
|
}}
|
|
|
|
/>
|
2021-10-28 01:48:15 +08:00
|
|
|
<Styled.Hint id="sharedNotesEscapeHint" aria-hidden>
|
2021-10-04 21:18:40 +08:00
|
|
|
{intl.formatMessage(intlMessages.tipLabel)}
|
2021-10-28 01:48:15 +08:00
|
|
|
</Styled.Hint>
|
|
|
|
</Styled.Note>
|
2021-10-04 21:18:40 +08:00
|
|
|
);
|
|
|
|
};
|
2018-12-13 04:10:27 +08:00
|
|
|
|
|
|
|
Note.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default injectWbResizeEvent(injectIntl(Note));
|