diff --git a/web/components/groups/discussion.tsx b/web/components/groups/discussion.tsx index 69bb1fde..a4a83745 100644 --- a/web/components/groups/discussion.tsx +++ b/web/components/groups/discussion.tsx @@ -33,6 +33,7 @@ export function Discussion(props: { const [scrollToMessageRef, setScrollToMessageRef] = useState(null) const [replyToUsername, setReplyToUsername] = useState('') + const [inputRef, setInputRef] = useState(null) const router = useRouter() useEffect(() => { @@ -40,8 +41,9 @@ export function Discussion(props: { }, [scrollToMessageRef]) useEffect(() => { - scrollToBottomRef?.scrollIntoView() - }, [isSubmitting, scrollToBottomRef]) + if (!isSubmitting) + scrollToBottomRef?.scrollTo({ top: scrollToBottomRef?.scrollHeight || 0 }) + }, [scrollToBottomRef, isSubmitting]) useEffect(() => { const elementInUrl = router.asPath.split('#')[1] @@ -65,6 +67,7 @@ export function Discussion(props: { setMessageText('') setIsSubmitting(false) setReplyToUsername('') + inputRef?.focus() } return ( @@ -73,8 +76,9 @@ export function Discussion(props: { className={ 'max-h-[65vh] w-full space-y-2 overflow-x-hidden overflow-y-scroll' } + ref={setScrollToBottomRef} > - {messages.map((message, i) => ( + {messages.map((message) => ( @@ -116,6 +118,7 @@ export function Discussion(props: { submitComment={submitMessage} isSubmitting={isSubmitting} enterToSubmit={true} + setRef={setInputRef} /> @@ -128,58 +131,62 @@ const GroupMessage = memo(function GroupMessage_(props: { user: User | null | undefined comment: Comment group: Group - truncate?: boolean - smallAvatar?: boolean onReplyClick?: (comment: Comment) => void setRef?: (ref: HTMLDivElement) => void highlight?: boolean }) { - const { comment, truncate, onReplyClick, group, setRef, highlight, user } = - props + const { comment, onReplyClick, group, setRef, highlight, user } = props const { text, userUsername, userName, userAvatarUrl, createdTime } = comment + const isCreatorsComment = user && comment.userId === user.id return ( - - -
-
- {' '} - -
+ + {!isCreatorsComment && ( + + + + )} + {!isCreatorsComment ? ( + + ) : ( + {'You'} + )} + + + - {onReplyClick && ( - - )} -
-
+ + {!isCreatorsComment && onReplyClick && ( + + )} + ) })