From f1a484cc662174717118bff1274aa473f5fa6ad9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 4 Nov 2022 22:05:49 +0300 Subject: Fix editing --- vnext/src/ui/Comment.js | 71 +++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 47 deletions(-) (limited to 'vnext/src/ui/Comment.js') diff --git a/vnext/src/ui/Comment.js b/vnext/src/ui/Comment.js index 45c80187..717d62e9 100644 --- a/vnext/src/ui/Comment.js +++ b/vnext/src/ui/Comment.js @@ -1,76 +1,53 @@ import { useEffect, useRef, useState } from 'react'; +import MessageInput from './MessageInput'; import Avatar from './Avatar'; import { UserLink } from './UserInfo'; import Button from './Button'; -import defaultAvatar from '../assets/av-96.png'; -import MessageInput from './MessageInput'; -import { fetchUserUri } from '../api'; -import { chatItemStyle } from './helpers/BubbleStyle'; import { format, embedUrls } from '../utils/embed'; -import { useVisitor } from './VisitorContext'; -let isMounted; +import { chatItemStyle } from './helpers/BubbleStyle'; +import { useVisitor } from './VisitorContext'; /** * @param {{ - msg: import('../api').Message, + visitor: import('../client').SecureUser, + msg: import('../client').Message, draft: string, active: number, - setActive: function, - onStartEditing: function, - postComment: function - }} props + setActive: Function, + onStartEditing: Function, + postComment: function({body:string, attach: string | File}) : void + }} props props + * @returns React.ReactElement */ export default function Comment({ msg, draft, active, setActive, onStartEditing, postComment }) { - const embedRef = useRef(); - const msgRef = useRef(); const [visitor] = useVisitor(); - const [author, setAuthor] = useState(msg.user); + /** @type {React.MutableRefObject} */ + const embedRef = useRef(null); + /** @type {React.MutableRefObject} */ + const msgRef = useRef(null); + const [author] = useState(msg.user); useEffect(() => { - if (msgRef.current) { + if (msgRef.current && embedRef.current) { embedUrls(msgRef.current.querySelectorAll('a'), embedRef.current); if (!embedRef.current.hasChildNodes()) { embedRef.current.style.display = 'none'; } } }, []); - const userRef = useRef(author); - useEffect(() => { - isMounted = true; - if (userRef.current.uri) { - fetchUserUri(userRef.current.uri).then(remote_user => { - if (isMounted) { - setAuthor({ - uid: 0, - uname: remote_user.preferredUsername, - avatar: remote_user.icon && remote_user.icon.url, - uri: author.uri - }); - } - }).catch(e => { - setAuthor({ - uid: 0, - uname: userRef.current.uri, - uri: author.uri, - avatar: defaultAvatar - }); - }); - } - return () => { - isMounted = false; - }; - }, [author.uri, msg.user]); return (
- {msg.replyto > 0 && + { + msg.to && msg.replyto && msg.replyto > 0 && ( - )} + ) + }
@@ -92,7 +69,7 @@ export default function Comment({ msg, draft, active, setActive, onStartEditing, }
{ - active === msg.rid && Write a comment... + active === msg.rid && }
{ @@ -118,8 +95,8 @@ export default function Comment({ msg, draft, active, setActive, onStartEditing, ); } /** - * @type React.CSSProperties + * @type {React.CSSProperties} */ - const linkStyle = { +const linkStyle = { cursor: 'pointer' -}; +}; \ No newline at end of file -- cgit v1.2.3