From f8429beef4a21c1d0be92281e94f801e663cc622 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 10 Aug 2022 20:22:00 -0700 Subject: [PATCH] Add+style system style chat message. Closes #1998 --- .../chat/ChatContainer/ChatContainer.tsx | 9 +++++ .../ChatSystemMessage.module.scss | 39 +++++++++++++++---- .../ChatSystemMessage/ChatSystemMessage.tsx | 22 +++++++++-- web/components/stores/ClientConfigStore.tsx | 3 ++ web/stories/ChatSystemMessage.stories.tsx | 21 +++++++++- 5 files changed, 83 insertions(+), 11 deletions(-) diff --git a/web/components/chat/ChatContainer/ChatContainer.tsx b/web/components/chat/ChatContainer/ChatContainer.tsx index 9f969f63f..5afeee2f3 100644 --- a/web/components/chat/ChatContainer/ChatContainer.tsx +++ b/web/components/chat/ChatContainer/ChatContainer.tsx @@ -12,6 +12,7 @@ import { ChatMessage } from '../../../interfaces/chat-message.model'; import { ChatTextField, ChatUserMessage } from '..'; import ChatModeratorNotification from '../ChatModeratorNotification/ChatModeratorNotification'; import ChatActionMessage from '../ChatAction/ChatActionMessage'; +import ChatSystemMessage from '../ChatSystemMessage/ChatSystemMessage'; interface Props { messages: ChatMessage[]; @@ -95,6 +96,14 @@ export default function ChatContainer(props: Props) { return getConnectedInfoMessage(message); case MessageType.USER_JOINED: return getUserJoinedMessage(message as ChatMessage); + case MessageType.SYSTEM: + return ( + + ); default: return null; diff --git a/web/components/chat/ChatSystemMessage/ChatSystemMessage.module.scss b/web/components/chat/ChatSystemMessage/ChatSystemMessage.module.scss index 16a4c21b2..c475ec419 100644 --- a/web/components/chat/ChatSystemMessage/ChatSystemMessage.module.scss +++ b/web/components/chat/ChatSystemMessage/ChatSystemMessage.module.scss @@ -1,13 +1,38 @@ -@import 'styles/mixins.scss'; - .chatSystemMessage { - background-color: var(--theme-unknown-2); + background: var(--theme-background-secondary); + background: linear-gradient( + 70deg, + rgb(78, 54, 114) 0%, + rgb(65, 28, 139) 40%, + rgb(83, 67, 130) 80% + ); margin: 5px; - border-radius: 15px; - border-color: rgba(0, 0, 0, 0.3); + border-radius: 5px; border-width: 1px; border-style: solid; - padding: 10px 10px; + padding: 12px 12px; max-width: 400px; - @include flexCenter; + + .user { + display: flex; + align-items: center; + font-family: var(--theme-header-font-family); + font-weight: bold; + color: white; + } + .message { + color: white; + + p { + color: white; + margin: unset; + } + + mark { + padding-left: 0.35em; + padding-right: 0.35em; + color: var(--theme-text-highlight); + background-color: var(--color-bg-highlight); + } + } } diff --git a/web/components/chat/ChatSystemMessage/ChatSystemMessage.tsx b/web/components/chat/ChatSystemMessage/ChatSystemMessage.tsx index b33386724..042a332b9 100644 --- a/web/components/chat/ChatSystemMessage/ChatSystemMessage.tsx +++ b/web/components/chat/ChatSystemMessage/ChatSystemMessage.tsx @@ -1,9 +1,25 @@ +/* eslint-disable react/no-danger */ +import { Highlight } from 'react-highlighter-ts'; +import { ChatMessage } from '../../../interfaces/chat-message.model'; import s from './ChatSystemMessage.module.scss'; interface Props { - message: string; + message: ChatMessage; + highlightString: string; } // eslint-disable-next-line @typescript-eslint/no-unused-vars -export default function ChatSystemMessage({ message }: Props) { - return
{message}
; +export default function ChatSystemMessage({ message, highlightString }: Props) { + const { body, user } = message; + const { displayName } = user; + + return ( +
+
+ {displayName} +
+ +
+ +
+ ); } diff --git a/web/components/stores/ClientConfigStore.tsx b/web/components/stores/ClientConfigStore.tsx index 880c1ac4c..1b6608a86 100644 --- a/web/components/stores/ClientConfigStore.tsx +++ b/web/components/stores/ClientConfigStore.tsx @@ -277,6 +277,9 @@ export function ClientConfigStore() { case MessageType.USER_JOINED: setChatMessages(currentState => [...currentState, message as ChatEvent]); break; + case MessageType.SYSTEM: + setChatMessages(currentState => [...currentState, message as ChatEvent]); + break; default: console.error('Unknown socket message type: ', message.type); } diff --git a/web/stories/ChatSystemMessage.stories.tsx b/web/stories/ChatSystemMessage.stories.tsx index 3f904e837..def581f9a 100644 --- a/web/stories/ChatSystemMessage.stories.tsx +++ b/web/stories/ChatSystemMessage.stories.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { ComponentStory, ComponentMeta } from '@storybook/react'; import ChatSystemMessage from '../components/chat/ChatSystemMessage/ChatSystemMessage'; import Mock from './assets/mocks/chatmessage-system.png'; +import { ChatMessage } from '../interfaces/chat-message.model'; export default { title: 'owncast/Chat/Messages/System', @@ -21,8 +22,26 @@ export default { const Template: ComponentStory = args => ; +const message: ChatMessage = JSON.parse(`{ + "type": "SYSTEM", + "id": "wY-MEXwnR", + "timestamp": "2022-04-28T20:30:27.001762726Z", + "user": { + "id": "h_5GQ6E7R", + "displayName": "Cool Server Name", + "createdAt": "2022-03-24T03:52:37.966584694Z", + "scopes": [] + }, + "body": "Test system message from the chat server."}`); + // eslint-disable-next-line @typescript-eslint/no-unused-vars export const Basic = Template.bind({}); Basic.args = { - message: 'This is a system message.', + message, +}; + +export const HighlightExample = Template.bind({}); +HighlightExample.args = { + message, + highlightString: 'chat', };