From 455d8f8169175b4a2a9ee14416785bbd2c489e44 Mon Sep 17 00:00:00 2001 From: t1enne Date: Fri, 1 Jul 2022 19:35:14 +0200 Subject: [PATCH] Few changes to chat. Changed the way the background is set on self sent messages and some styling. Fixed chat container not scrolling. Added 'go to bottom' button. --- .../ChatContainer/ChatContainer.module.scss | 10 +++- .../chat/ChatContainer/ChatContainer.tsx | 54 +++++++++++++------ .../ChatUserMessage.module.scss | 26 ++++++++- .../chat/ChatUserMessage/ChatUserMessage.tsx | 44 ++++++--------- 4 files changed, 87 insertions(+), 47 deletions(-) diff --git a/web/components/chat/ChatContainer/ChatContainer.module.scss b/web/components/chat/ChatContainer/ChatContainer.module.scss index f13fb0024..ffbd8fb37 100644 --- a/web/components/chat/ChatContainer/ChatContainer.module.scss +++ b/web/components/chat/ChatContainer/ChatContainer.module.scss @@ -1,8 +1,16 @@ - .chatHeader { text-align: center; + font-weight: bold; padding: 5px 0; color: var(--text-color-secondary); border-bottom: 1px solid var(--color-owncast-gray-700); font-variant: small-caps; } + +.toBottomWrap { + display: flex; + width: 100%; + justify-content: center; + position: absolute; + bottom: 5px; +} diff --git a/web/components/chat/ChatContainer/ChatContainer.tsx b/web/components/chat/ChatContainer/ChatContainer.tsx index bb0bcb084..43383fddc 100644 --- a/web/components/chat/ChatContainer/ChatContainer.tsx +++ b/web/components/chat/ChatContainer/ChatContainer.tsx @@ -1,8 +1,7 @@ -import { Spin } from 'antd'; +import { Button, Spin } from 'antd'; import { Virtuoso } from 'react-virtuoso'; -import { useMemo, useRef } from 'react'; -import { LoadingOutlined } from '@ant-design/icons'; - +import { useState, useMemo, useRef } from 'react'; +import { LoadingOutlined, VerticalAlignBottomOutlined } from '@ant-design/icons'; import { MessageType, NameChangeEvent } from '../../../interfaces/socket-events'; import s from './ChatContainer.module.scss'; import { ChatMessage } from '../../../interfaces/chat-message.model'; @@ -19,6 +18,8 @@ interface Props { export default function ChatContainer(props: Props) { const { messages, loading, usernameToHighlight, chatUserId, isModerator } = props; + const [atBottom, setAtBottom] = useState(false); + // const [showButton, setShowButton] = useState(false); const chatContainerRef = useRef(null); const spinIcon = ; @@ -34,12 +35,12 @@ export default function ChatContainer(props: Props) { ); }; - const getViewForMessage = message => { + const getViewForMessage = (message: ChatMessage | NameChangeEvent) => { switch (message.type) { case MessageType.CHAT: return ( ); case MessageType.NAME_CHANGE: - return getNameChangeViewForMessage(message); + return getNameChangeViewForMessage(message as NameChangeEvent); default: return null; } @@ -55,17 +56,36 @@ export default function ChatContainer(props: Props) { const MessagesTable = useMemo( () => ( - getViewForMessage(message)} - followOutput="auto" - alignToBottom - /> + <> + getViewForMessage(message)} + followOutput="auto" + alignToBottom + atBottomStateChange={bottom => setAtBottom(bottom)} + /> + {!atBottom && ( +
+ +
+ )} + ), - [messages, usernameToHighlight, chatUserId, isModerator], + [messages, usernameToHighlight, chatUserId, isModerator, atBottom], ); return ( diff --git a/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss b/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss index 80615872d..457eaf63c 100644 --- a/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss +++ b/web/components/chat/ChatUserMessage/ChatUserMessage.module.scss @@ -1,9 +1,20 @@ .root { position: relative; font-size: 0.9rem; - padding: 5px; + padding: 5px 15px 5px 5px; padding-left: 1rem; - margin: 8px 5px; + // animation: chatFadeIn .1s ease-in; + .background { + position: absolute; + top: 0px; + left: 0px; + width: 100%; + height: 100%; + background-color: currentColor; + opacity: 0.07; + border-radius: .25rem; + overflow: hidden; + } .user { font: var(--theme-header-font-family); color: var(--color-owncast-grey-100); @@ -56,3 +67,14 @@ } } } + + +@keyframes chatFadeIn { + from { + opacity: 0; + } + to { + opacity: 1; + } +} + diff --git a/web/components/chat/ChatUserMessage/ChatUserMessage.tsx b/web/components/chat/ChatUserMessage/ChatUserMessage.tsx index 333772e1d..2a52634f7 100644 --- a/web/components/chat/ChatUserMessage/ChatUserMessage.tsx +++ b/web/components/chat/ChatUserMessage/ChatUserMessage.tsx @@ -20,7 +20,6 @@ export default function ChatUserMessage({ showModeratorMenu, renderAsPersonallySent, // Move the border to the right and render a background }: Props) { - const [bgColor, setBgColor] = useState(); const { body, user, timestamp } = message; const { displayName, displayColor } = user; @@ -28,38 +27,29 @@ export default function ChatUserMessage({ const formattedTimestamp = `Sent at ${formatTimestamp(timestamp)}`; const [formattedMessage, setFormattedMessage] = useState(body); - useEffect(() => { - if (renderAsPersonallySent) setBgColor(getBgColor(displayColor)); - }, []); - useEffect(() => { setFormattedMessage(he.decode(body)); }, [message]); return ( -
-
- {displayName} +
+
+
+ {displayName} +
+ +
{formattedMessage}
+
+ {showModeratorMenu &&
Moderator menu
} +
+
- -
{formattedMessage}
-
- {showModeratorMenu &&
Moderator menu
} -
); } - -function getBgColor(displayColor: number, alpha = 13) { - const root = document.querySelector(':root'); - const css = getComputedStyle(root); - const hexColor = css.getPropertyValue(`--theme-user-colors-${displayColor}`); - return hexColor.concat(alpha.toString()); -}