diff --git a/web-chat/src/App.tsx b/web-chat/src/App.tsx index b6949b28a9..937db54fb2 100644 --- a/web-chat/src/App.tsx +++ b/web-chat/src/App.tsx @@ -13,6 +13,35 @@ import { WakuContext } from './WakuContext'; import { ThemeProvider } from '@livechat/ui-kit'; import { generate } from 'server-name-generator'; +const themes = { + AuthorName: { + css: { + fontSize: '1.1em', + }, + }, + Message: { + css: { + margin: '0em', + padding: '0em', + fontSize: '0.83em', + }, + }, + MessageText: { + css: { + margin: '0em', + padding: '0.1em', + paddingLeft: '1em', + fontSize: '1.1em', + }, + }, + MessageGroup: { + css: { + margin: '0em', + padding: '0.2em', + }, + }, +}; + export const ChatContentTopic = 'dingpu'; export default function App() { @@ -82,7 +111,7 @@ export default function App() { style={{ height: '100vh', width: '100vw', overflow: 'hidden' }} > - + ( - - {currentMessage.message} - - )); - - return ( - - {listItems} - - + const messagesGroupedBySender = groupMessagesBySender(props.messages).map( + (currentMessageGroup) => ( + + {currentMessageGroup.map((currentMessage) => ( + + {currentMessage.message} + + ))} + + ) ); - function formatDisplayDate(message: ChatMessage) { - return message.timestamp.toLocaleString([], { - month: 'short', - day: 'numeric', - hour: 'numeric', - minute: '2-digit', - hour12: false, - }); + return ( + + {messagesGroupedBySender} + + + ); +} + +function groupMessagesBySender(messageArray: ChatMessage[]): ChatMessage[][] { + let currentSender = -1; + let lastNick = ''; + let messagesBySender: ChatMessage[][] = []; + let currentSenderMessage = 0; + + for (let currentMessage of messageArray) { + if (lastNick !== currentMessage.nick) { + currentSender++; + messagesBySender[currentSender] = []; + currentSenderMessage = 0; + lastNick = currentMessage.nick; + } + messagesBySender[currentSender][currentSenderMessage++] = currentMessage; } + return messagesBySender; +} + +function formatDisplayDate(message: ChatMessage): string { + return message.timestamp.toLocaleString([], { + month: 'short', + day: 'numeric', + hour: 'numeric', + minute: '2-digit', + hour12: false, + }); } const AlwaysScrollToBottom = (props: Props) => { diff --git a/web-chat/src/Room.tsx b/web-chat/src/Room.tsx index a0849f3e52..2ea40c291c 100644 --- a/web-chat/src/Room.tsx +++ b/web-chat/src/Room.tsx @@ -5,7 +5,7 @@ import { ChatContentTopic } from './App'; import ChatList from './ChatList'; import MessageInput from './MessageInput'; import { useWaku } from './WakuContext'; -import { TitleBar, MessageList } from '@livechat/ui-kit'; +import { TitleBar } from '@livechat/ui-kit'; interface Props { lines: ChatMessage[]; @@ -23,9 +23,7 @@ export default function Room(props: Props) { style={{ height: '98vh', display: 'flex', flexDirection: 'column' }} > - - - +