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.js70
1 files changed, 35 insertions, 35 deletions
diff --git a/vnext/src/ui/Chat.js b/vnext/src/ui/Chat.js
index 4fdeaac7..55b89d09 100644
--- a/vnext/src/ui/Chat.js
+++ b/vnext/src/ui/Chat.js
@@ -1,17 +1,17 @@
-import { useEffect, useState, useCallback } from 'react';
-import { useParams } from 'react-router-dom';
-import dayjs from 'dayjs';
-import utc from 'dayjs/plugin/utc';
-dayjs.extend(utc);
+import { useEffect, useState, useCallback } from 'react'
+import { useParams } from 'react-router-dom'
+import dayjs from 'dayjs'
+import utc from 'dayjs/plugin/utc'
+dayjs.extend(utc)
-import PM from './PM';
-import MessageInput from './MessageInput';
-import UserInfo from './UserInfo';
+import PM from './PM'
+import MessageInput from './MessageInput'
+import UserInfo from './UserInfo'
-import { getChat, pm } from '../api';
+import { getChat, pm } from '../api'
-import { useVisitor } from './VisitorContext';
-import { Helmet } from 'react-helmet';
+import { useVisitor } from './VisitorContext'
+import { Helmet } from 'react-helmet'
/**
*
@@ -24,48 +24,48 @@ import { Helmet } from 'react-helmet';
* @param {ChatProps} props
*/
export default function Chat(props) {
- const [visitor] = useVisitor();
- const [messages, setMessages] = useState([]);
- const params = useParams();
+ const [visitor] = useVisitor()
+ const [messages, setMessages] = useState([])
+ const params = useParams()
let loadChat = useCallback((uname) => {
- const { hash } = visitor;
+ const { hash } = visitor
if (hash && uname) {
getChat(uname)
.then(response => {
- setMessages(response.data);
- }).catch(console.log);
+ setMessages(response.data)
+ }).catch(console.log)
}
- }, [visitor]);
+ }, [visitor])
let onMessage = useCallback((json) => {
- const msg = JSON.parse(json.data);
+ const msg = JSON.parse(json.data)
if (msg.user.uname === params.user) {
setMessages((oldChat) => {
- return [msg, ...oldChat];
- });
+ return [msg, ...oldChat]
+ })
}
- }, [params.user]);
+ }, [params.user])
let onSend = async ({ body }) => {
- let result = false;
- let res = await pm(params.user, body).catch(console.error);
- result = res.status == 200;
- return result;
- };
+ let result = false
+ let res = await pm(params.user, body).catch(console.error)
+ result = res.status == 200
+ return result
+ }
useEffect(() => {
if (props.connection.addEventListener) {
- props.connection.addEventListener('msg', onMessage);
+ props.connection.addEventListener('msg', onMessage)
}
- loadChat(params.user);
- console.log(props.connection);
+ loadChat(params.user)
+ console.log(props.connection)
return () => {
if (props.connection.removeEventListener) {
- props.connection.removeEventListener('msg', onMessage);
+ props.connection.removeEventListener('msg', onMessage)
}
- };
- }, [props.connection, onMessage, loadChat, params.user]);
- const uname = params.user;
+ }
+ }, [props.connection, onMessage, loadChat, params.user])
+ const uname = params.user
return (
<div className="msg-cont">
<Helmet>
@@ -90,5 +90,5 @@ export default function Chat(props) {
)
}
</div>
- );
+ )
}