From f707d3d524d8d16e2bb780764f029d85fc57ecc0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 26 Jul 2019 13:22:00 +0300 Subject: prop-types -> jsdoc --- vnext/src/ui/Chat.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'vnext/src/ui/Chat.js') 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 (