aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/Chat.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-07-26 13:22:00 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:55 +0300
commitf707d3d524d8d16e2bb780764f029d85fc57ecc0 (patch)
tree1580074a665bd16c9744b5749c2a777700c5ae73 /vnext/src/ui/Chat.js
parent6016b0888e77497e15384f1cd024eb42672129a4 (diff)
prop-types -> jsdoc
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
-};