diff options
author | Vitaly Takmazov | 2022-11-20 05:59:45 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:59 +0300 |
commit | 0930332430de0b9f123ecb556949c8db54a92359 (patch) | |
tree | 61eca561df695a48b8ba2d1cd47744e98f14b61d /vnext/src/ui/Chat.js | |
parent | d3cfc10a2087579f44b3bf91576c2f4ca518326a (diff) |
Fix comment/edit/pm
Diffstat (limited to 'vnext/src/ui/Chat.js')
-rw-r--r-- | vnext/src/ui/Chat.js | 19 |
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} /> ) } |