From 0930332430de0b9f123ecb556949c8db54a92359 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 20 Nov 2022 05:59:45 +0300 Subject: Fix comment/edit/pm --- vnext/src/ui/Chat.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'vnext/src/ui/Chat.js') 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) {