bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/alert/push-alert/component.jsx

80 lines
1.8 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
2017-10-27 01:14:50 +08:00
import injectNotify from '/imports/ui/components/toast/inject-notify/component';
2018-10-17 01:48:27 +08:00
import { Session } from 'meteor/session';
2021-05-18 04:25:07 +08:00
import { PANELS, ACTIONS } from '../../../layout/enums';
const propTypes = {
notify: PropTypes.func.isRequired,
onOpen: PropTypes.func.isRequired,
2018-10-25 23:20:37 +08:00
chatId: PropTypes.string.isRequired,
2019-01-14 21:23:35 +08:00
title: PropTypes.node.isRequired,
2018-10-25 23:20:37 +08:00
content: PropTypes.node.isRequired,
2019-01-14 21:23:35 +08:00
alertDuration: PropTypes.number.isRequired,
};
2017-10-27 01:14:50 +08:00
class ChatPushAlert extends PureComponent {
2021-05-18 04:25:07 +08:00
constructor(props) {
super(props);
this.showNotify = this.showNotify.bind(this);
this.componentDidMount = this.showNotify;
this.componentDidUpdate = this.showNotify;
this.link = this.link.bind(this);
}
2019-01-22 19:42:03 +08:00
2021-05-18 04:25:07 +08:00
link(title, chatId) {
const { newLayoutContextDispatch } = this.props;
2019-01-22 19:42:03 +08:00
2018-10-17 01:48:27 +08:00
return (
<div
2019-01-14 21:23:35 +08:00
key={chatId}
2018-10-17 01:48:27 +08:00
role="button"
2019-01-14 21:23:35 +08:00
aria-label={title}
2018-10-25 23:20:37 +08:00
tabIndex={0}
2018-10-17 01:48:27 +08:00
onClick={() => {
2021-05-18 04:25:07 +08:00
newLayoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: true,
});
newLayoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.CHAT,
});
window.dispatchEvent(new Event('panelChanged'));
2018-12-18 23:15:51 +08:00
}}
2019-01-22 19:42:03 +08:00
onKeyPress={() => null}
2018-10-17 01:48:27 +08:00
>
2019-01-14 21:23:35 +08:00
{title}
2018-10-17 01:48:27 +08:00
</div>
);
}
2017-10-27 01:14:50 +08:00
showNotify() {
const {
notify,
onOpen,
chatId,
2019-01-14 21:23:35 +08:00
title,
content,
2019-01-14 21:23:35 +08:00
alertDuration,
2017-10-27 01:14:50 +08:00
} = this.props;
2018-06-15 22:37:57 +08:00
return notify(
2021-05-18 04:25:07 +08:00
this.link(title, chatId),
2018-06-15 22:37:57 +08:00
'info',
'chat',
2019-01-14 21:23:35 +08:00
{ onOpen, autoClose: alertDuration },
2021-05-18 04:25:07 +08:00
this.link(content, chatId),
2018-06-15 22:37:57 +08:00
true,
);
2017-10-27 01:14:50 +08:00
}
render() {
return null;
}
}
2018-08-15 10:35:58 +08:00
ChatPushAlert.propTypes = propTypes;
2017-10-27 01:14:50 +08:00
2018-08-15 10:35:58 +08:00
export default injectNotify(ChatPushAlert);