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

67 lines
1.4 KiB
React
Raw Normal View History

2017-10-27 01:14:50 +08:00
import React from 'react';
import PropTypes from 'prop-types';
2017-10-27 01:14:50 +08:00
import _ from 'lodash';
import injectNotify from '/imports/ui/components/toast/inject-notify/component';
2018-10-17 01:48:27 +08:00
import { Session } from 'meteor/session';
import { styles } from '../../styles.scss';
2018-08-15 10:35:58 +08:00
const ALERT_INTERVAL = 2000; // 2 seconds
const ALERT_LIFETIME = 4000; // 4 seconds
const propTypes = {
notify: PropTypes.func.isRequired,
onOpen: PropTypes.func.isRequired,
};
2017-10-27 01:14:50 +08:00
2018-08-15 10:35:58 +08:00
class ChatPushAlert extends React.Component {
static link(message, chatId) {
2018-10-17 01:48:27 +08:00
return (
<div
role="button"
label={message}
onClick={() => {
Session.set('isUserListOpen', true);
Session.set('isChatOpen', true);
Session.set('isChatOpen', chatId);
}}
>
{ message }
</div>
);
}
2017-10-27 01:14:50 +08:00
constructor(props) {
super(props);
2018-08-15 10:35:58 +08:00
this.showNotify = _.debounce(this.showNotify.bind(this), ALERT_INTERVAL);
2017-10-27 01:14:50 +08:00
this.componentDidMount = this.showNotify;
this.componentDidUpdate = this.showNotify;
}
showNotify() {
const {
notify,
onOpen,
chatId,
message,
content,
2017-10-27 01:14:50 +08:00
} = this.props;
2018-06-15 22:37:57 +08:00
return notify(
2018-08-15 10:35:58 +08:00
ChatPushAlert.link(message, chatId),
2018-06-15 22:37:57 +08:00
'info',
'chat',
2018-08-15 10:35:58 +08:00
{ onOpen, autoClose: ALERT_LIFETIME },
ChatPushAlert.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);