From bd869ed54a5f0f25ff0a147de21687c611a6ae26 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Thu, 28 Nov 2024 10:23:28 +0000 Subject: [PATCH] FS-73 Show message in sidebar --- frontend/src/app.tsx | 21 +++++++++++++------- frontend/src/components/chat.tsx | 17 ++++++++++++++-- frontend/src/components/message.module.css | 7 +++++++ frontend/src/components/message.tsx | 23 +++++++++++++++++++++- frontend/src/useMessages.ts | 5 +++++ 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/frontend/src/app.tsx b/frontend/src/app.tsx index a36cdb3d..33f22b40 100644 --- a/frontend/src/app.tsx +++ b/frontend/src/app.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect } from 'react'; import styles from './app.module.css'; import { Chat } from './components/chat'; import { Input } from './components/input'; @@ -15,10 +15,10 @@ export const App = () => { suggestions, resetMessages, initSuggestions, + selectMessage, + selectedMessage, } = useMessages(); - const [showSidebar, setShowSidebar] = useState(false); - useEffect(() => { initSuggestions(); }, []); @@ -27,23 +27,30 @@ export const App = () => { <>
- {showSidebar && ( + {selectedMessage && (
setShowSidebar(false)} + onClick={() => selectMessage(null)} />
-

Sidebar content

+

id: {selectedMessage.id}

+

message: {selectedMessage.content}

+

time: {selectedMessage.time}

)}
- + void; } const mapWsMessageToConfirmation = ( @@ -23,7 +26,12 @@ const mapWsMessageToConfirmation = ( return { id: parts[0], requestMessage: parts[1], result: null }; }; -export const Chat = ({ messages, waiting }: ChatProps) => { +export const Chat = ({ + messages, + waiting, + selectedMessage, + selectMessage, +}: ChatProps) => { const containerRef = React.useRef(null); const { lastMessage, send } = useContext(WebsocketContext); const [chart, setChart] = useState(undefined); @@ -55,7 +63,12 @@ export const Chat = ({ messages, waiting }: ChatProps) => { />
{messages.map((message, index) => ( - + ))} {chart && Generated chart} {waiting && } diff --git a/frontend/src/components/message.module.css b/frontend/src/components/message.module.css index 223576e0..6df39961 100644 --- a/frontend/src/components/message.module.css +++ b/frontend/src/components/message.module.css @@ -71,3 +71,10 @@ font-size: 16px; white-space: pre-wrap; } + +.selectMessage { + margin-left: 72px; + margin-bottom: 8px; + position: relative; + top: -4px; +} diff --git a/frontend/src/components/message.tsx b/frontend/src/components/message.tsx index 40c970c5..56d01b74 100644 --- a/frontend/src/components/message.tsx +++ b/frontend/src/components/message.tsx @@ -4,6 +4,8 @@ import styles from './message.module.css'; import UserIcon from '../icons/account-circle.svg'; import BotIcon from '../icons/logomark.svg'; import ChevronIcon from '../icons/chevron.svg'; +import OpenGridIcon from '../icons/open-grid.svg'; +import { Button } from './button'; export enum Role { User = 'User', @@ -20,6 +22,8 @@ export interface Message { export interface MessageProps { message: Message; + selectedMessage: Message | null; + selectMessage: (message: Message | null) => void; } export interface MessageStyle { @@ -38,7 +42,11 @@ const roleStyleMap: Record = { }, }; -export const MessageComponent = ({ message }: MessageProps) => { +export const MessageComponent = ({ + message, + selectMessage, + selectedMessage, +}: MessageProps) => { const { content, role, reasoning } = message; const { class: roleClass, icon } = roleStyleMap[role]; @@ -51,6 +59,19 @@ export const MessageComponent = ({ message }: MessageProps) => {

{content}

+ {role == Role.Bot && ( +
+
+ )} {role == Role.Bot && reasoning && ( <>
void; resetMessages: () => void; initSuggestions: () => void; + selectMessage: (message: Message | null) => void; messages: Message[]; suggestions: string[]; waiting: boolean; + selectedMessage: Message | null; } export const useMessages = (): UseMessagesHook => { const [waiting, setWaiting] = useState(false); const [messages, setMessages] = useState([starterMessage]); const [suggestions, setSuggestions] = useState([]); + const [selectedMessage, selectMessage] = useState(null); const fetchSuggestions = useCallback(async () => { const newSuggestions = await getSuggestions(); @@ -90,5 +93,7 @@ export const useMessages = (): UseMessagesHook => { waiting, resetMessages, initSuggestions: fetchSuggestions, + selectedMessage, + selectMessage, }; };