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.js19
1 files changed, 9 insertions, 10 deletions
diff --git a/vnext/src/ui/Chat.js b/vnext/src/ui/Chat.js
index c1151daf..392b12a0 100644
--- a/vnext/src/ui/Chat.js
+++ b/vnext/src/ui/Chat.js
@@ -26,16 +26,15 @@ import { Helmet } from 'react-helmet';
*/
export default function Chat(props) {
const [visitor] = useVisitor();
- const [chats, setChats] = useState([]);
+ const [messages, setMessages] = useState([]);
const params = useParams();
let loadChat = useCallback((uname) => {
const { hash } = visitor;
- setChats([]);
if (hash && uname) {
getChat(uname)
.then(response => {
- setChats(response.data);
+ setMessages(response.data);
}).catch(console.log);
}
}, [visitor]);
@@ -43,17 +42,17 @@ export default function Chat(props) {
let onMessage = useCallback((json) => {
const msg = JSON.parse(json.data);
if (msg.user.uname === params.user) {
- setChats((oldChat) => {
+ setMessages((oldChat) => {
return [msg, ...oldChat];
});
}
}, [params.user]);
- let onSend = (template) => {
- pm(template.to.uname, template.body)
- .then(() => {
- loadChat(params.user);
- }).catch(console.log);
+ let onSend = async ({ body }) => {
+ let result = false;
+ let res = await pm(params.user, body).catch(console.error);
+ result = res.status == 200;
+ return result;
};
useEffect(() => {
if (props.connection.addEventListener) {
@@ -78,7 +77,7 @@ export default function Chat(props) {
<div className="chatroom">
<ul className="Chat_messages">
{
- chats.map((chat) =>
+ messages.map((chat) =>
<PM key={dayjs.utc(chat.timestamp).valueOf()} chat={chat} {...props} />
)
}