aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/Chat.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/src/ui/Chat.js')
-rw-r--r--vnext/src/ui/Chat.js44
1 files changed, 23 insertions, 21 deletions
diff --git a/vnext/src/ui/Chat.js b/vnext/src/ui/Chat.js
index a1254a10..00e8eb3c 100644
--- a/vnext/src/ui/Chat.js
+++ b/vnext/src/ui/Chat.js
@@ -1,7 +1,4 @@
import React, { useEffect, useState, useCallback } from 'react';
-import PropTypes from 'prop-types';
-import ReactRouterPropTypes from 'react-router-prop-types';
-import { UserType } from './Types';
import moment from 'moment';
import PM from './PM';
@@ -12,20 +9,19 @@ import { getChat, pm } from '../api';
import './Chat.css';
+/**
+ * @typedef {Object} ChatProps
+ * @property {import('../api').SecureUser} visitor
+ * @property {EventSource} connection
+ * @property {import('react-router').match} match
+ */
+
+/**
+ * Chat component
+ * @param {ChatProps} props
+ */
export default function Chat(props) {
const [chats, setChats] = useState([]);
- useEffect(() => {
- if (props.connection.addEventListener) {
- props.connection.addEventListener('msg', onMessage);
- }
- loadChat(props.match.params.user);
- console.log(props.connection);
- return () => {
- if (props.connection.removeEventListener) {
- props.connection.removeEventListener('msg', onMessage);
- }
- };
- }, [props.connection, onMessage, loadChat, props.match.params.user]);
let loadChat = useCallback((uname) => {
const { hash } = props.visitor;
@@ -53,6 +49,18 @@ export default function Chat(props) {
loadChat(props.match.params.user);
}).catch(console.log);
};
+ useEffect(() => {
+ if (props.connection.addEventListener) {
+ props.connection.addEventListener('msg', onMessage);
+ }
+ loadChat(props.match.params.user);
+ console.log(props.connection);
+ return () => {
+ if (props.connection.removeEventListener) {
+ props.connection.removeEventListener('msg', onMessage);
+ }
+ };
+ }, [props.connection, onMessage, loadChat, props.match.params.user]);
const uname = props.match.params.user;
return (
<div className="msg-cont">
@@ -77,9 +85,3 @@ export default function Chat(props) {
</div>
);
}
-
-Chat.propTypes = {
- visitor: UserType.isRequired,
- match: ReactRouterPropTypes.match.isRequired,
- connection: PropTypes.object.isRequired
-};