From 12f4a93b211a8f4acdcfd3b653c9f1fb81623225 Mon Sep 17 00:00:00 2001 From: SuperTurk Date: Fri, 5 Jan 2024 11:02:05 +0100 Subject: [PATCH 1/9] refactor: Design of messages --- libs/react-components/src/elements/Avatar.tsx | 27 +++--- .../react-components/src/messages/Message.tsx | 55 ++++++------ .../src/messages/components/Author.tsx | 85 ++++++++++--------- .../src/messages/components/DetailsButton.tsx | 2 + .../src/messages/components/MessageTime.tsx | 2 +- 5 files changed, 84 insertions(+), 87 deletions(-) diff --git a/libs/react-components/src/elements/Avatar.tsx b/libs/react-components/src/elements/Avatar.tsx index 91cf33206c..6fd392363a 100644 --- a/libs/react-components/src/elements/Avatar.tsx +++ b/libs/react-components/src/elements/Avatar.tsx @@ -1,25 +1,22 @@ import Avatar from '@mui/material/Avatar'; -import Tooltip from '@mui/material/Tooltip'; import { type IAvatarElement } from 'client-types/'; interface Props { - element: IAvatarElement; author: string; + bgColor?: string; + element?: IAvatarElement; } -const AvatarElement = ({ element, author }: Props) => { - if (!element.url) { - return null; - } - - return ( - - - - - - ); -}; +const AvatarElement = ({ element, author, bgColor }: Props) => ( + + + {author[0]} + + +); export { AvatarElement }; diff --git a/libs/react-components/src/messages/Message.tsx b/libs/react-components/src/messages/Message.tsx index c59921c8d0..8e387dceda 100644 --- a/libs/react-components/src/messages/Message.tsx +++ b/libs/react-components/src/messages/Message.tsx @@ -88,7 +88,7 @@ const Message = memo( @@ -100,35 +100,30 @@ const Message = memo( overflowX: 'auto' }} > - - - - setShowDetails(!showDetails)} - loading={isRunning && isLast} - /> - {!isRunning && isLast && isAsk && ( - - )} - {actions?.length ? ( - - ) : null} - - + + + + setShowDetails(!showDetails)} + loading={isRunning && isLast} + /> + {!isRunning && isLast && isAsk && ( + + )} + {actions?.length ? ( + + ) : null} + + + {message.steps && showDetails && ( diff --git a/libs/react-components/src/messages/components/Author.tsx b/libs/react-components/src/messages/components/Author.tsx index 7653738416..e14fac94d4 100644 --- a/libs/react-components/src/messages/components/Author.tsx +++ b/libs/react-components/src/messages/components/Author.tsx @@ -3,7 +3,7 @@ import { useContext } from 'react'; import { AvatarElement } from 'src/elements/Avatar'; import Box from '@mui/material/Box'; -import Tooltip from '@mui/material/Tooltip'; +import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { useColorForName } from 'hooks/useColors'; @@ -15,58 +15,61 @@ import { MessageTime } from './MessageTime'; interface Props { message: IStep; show?: boolean; + children?: React.ReactNode; } -export const AUTHOR_BOX_WIDTH = 70; +export const AUTHOR_BOX_WIDTH = 24; -const Author = ({ message, show }: Props) => { +const Author = ({ message, show, children }: Props) => { const context = useContext(MessageContext); const getColorForName = useColorForName(context.uiName); - const author = message.name; const isUser = message.type === 'user_message'; + const author = isUser ? 'You' : message.name; const avatarEl = context.avatars.find((e) => e.name === author); - const avatar = show && avatarEl && ( - - ); - - const name = show && ( - - - {author} - - - ); - - const display = avatar || name; - return ( - <> - - {display} - - - {(!!message.indent || message.parentId) && ( - + + {show ? ( + + + {(!!message.indent || message.parentId) && ( + + )} + + ) : ( + )} - + + + + {show ? ( + + {author} + + ) : null} + + + {children} + + ); }; diff --git a/libs/react-components/src/messages/components/DetailsButton.tsx b/libs/react-components/src/messages/components/DetailsButton.tsx index d036b0b335..5a7fbb8f06 100644 --- a/libs/react-components/src/messages/components/DetailsButton.tsx +++ b/libs/react-components/src/messages/components/DetailsButton.tsx @@ -59,7 +59,9 @@ const DetailsButton = ({ message, opened, onClick, loading }: Props) => { return ( : undefined diff --git a/libs/react-components/src/messages/components/MessageTime.tsx b/libs/react-components/src/messages/components/MessageTime.tsx index e47a35f2c6..5b11c59d7b 100644 --- a/libs/react-components/src/messages/components/MessageTime.tsx +++ b/libs/react-components/src/messages/components/MessageTime.tsx @@ -17,7 +17,7 @@ const MessageTime = ({ timestamp }: Props) => { } const date = new Date(timestamp).toLocaleTimeString(undefined, dateOptions); return ( - + {date} ); From da8ca4233c5d668a1aa22db0a622988fffb7b409 Mon Sep 17 00:00:00 2001 From: Willy Douhard Date: Fri, 5 Jan 2024 13:38:40 +0100 Subject: [PATCH 2/9] ui fixes --- frontend/src/assets/chevronLeft.tsx | 22 ++++++++++++ frontend/src/assets/chevronRight.tsx | 22 ++++++++++++ frontend/src/assets/chevronUp.tsx | 22 ++++++++++++ frontend/src/assets/user.tsx | 22 ++++++++++++ .../atoms/buttons/userButton/avatar.tsx | 8 +++-- .../organisms/chat/history/index.tsx | 5 +-- frontend/src/components/organisms/header.tsx | 2 +- .../organisms/threadHistory/sidebar/index.tsx | 12 +++++-- libs/react-components/hooks/useColors.tsx | 36 +++++++++---------- libs/react-components/src/Code.tsx | 3 +- libs/react-components/src/elements/Avatar.tsx | 8 ++++- .../react-components/src/messages/Message.tsx | 2 +- .../messages/components/AskUploadButton.tsx | 3 +- .../src/messages/components/Author.tsx | 4 +-- .../src/messages/components/MessageTime.tsx | 7 +++- 15 files changed, 144 insertions(+), 34 deletions(-) create mode 100644 frontend/src/assets/chevronLeft.tsx create mode 100644 frontend/src/assets/chevronRight.tsx create mode 100644 frontend/src/assets/chevronUp.tsx create mode 100644 frontend/src/assets/user.tsx diff --git a/frontend/src/assets/chevronLeft.tsx b/frontend/src/assets/chevronLeft.tsx new file mode 100644 index 0000000000..03f77bfb75 --- /dev/null +++ b/frontend/src/assets/chevronLeft.tsx @@ -0,0 +1,22 @@ +import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon'; + +const ChevronLeftIcon = (props: SvgIconProps) => { + return ( + + + + + + + ); +}; + +export default ChevronLeftIcon; diff --git a/frontend/src/assets/chevronRight.tsx b/frontend/src/assets/chevronRight.tsx new file mode 100644 index 0000000000..82224a7ae7 --- /dev/null +++ b/frontend/src/assets/chevronRight.tsx @@ -0,0 +1,22 @@ +import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon'; + +const ChevronRightIcon = (props: SvgIconProps) => { + return ( + + + + + + + ); +}; + +export default ChevronRightIcon; diff --git a/frontend/src/assets/chevronUp.tsx b/frontend/src/assets/chevronUp.tsx new file mode 100644 index 0000000000..77cd159385 --- /dev/null +++ b/frontend/src/assets/chevronUp.tsx @@ -0,0 +1,22 @@ +import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon'; + +const ChevronUpIcon = (props: SvgIconProps) => { + return ( + + + + + + + ); +}; + +export default ChevronUpIcon; diff --git a/frontend/src/assets/user.tsx b/frontend/src/assets/user.tsx new file mode 100644 index 0000000000..d55150eb10 --- /dev/null +++ b/frontend/src/assets/user.tsx @@ -0,0 +1,22 @@ +import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon'; + +const UserIcon = (props: SvgIconProps) => { + return ( + + + + + + + ); +}; + +export default UserIcon; diff --git a/frontend/src/components/atoms/buttons/userButton/avatar.tsx b/frontend/src/components/atoms/buttons/userButton/avatar.tsx index 50dacffe0b..2de275f29a 100644 --- a/frontend/src/components/atoms/buttons/userButton/avatar.tsx +++ b/frontend/src/components/atoms/buttons/userButton/avatar.tsx @@ -2,6 +2,8 @@ import { useAuth } from 'api/auth'; import { Avatar, Box } from '@mui/material'; +import UserIcon from 'assets/user'; + export default function UserAvatar() { const { user } = useAuth(); @@ -16,7 +18,7 @@ export default function UserAvatar() { }} src={user.metadata?.image || undefined} > - {user.identifier?.[0]} + {user.identifier?.[0]?.toUpperCase()} ); } else { @@ -29,7 +31,9 @@ export default function UserAvatar() { bgcolor: 'primary.main', color: 'primary.contrastText' }} - /> + > + + ); } diff --git a/frontend/src/components/organisms/chat/history/index.tsx b/frontend/src/components/organisms/chat/history/index.tsx index 27a2ebd252..e347d81fc5 100644 --- a/frontend/src/components/organisms/chat/history/index.tsx +++ b/frontend/src/components/organisms/chat/history/index.tsx @@ -4,7 +4,6 @@ import { useRef, useState } from 'react'; import { useRecoilState } from 'recoil'; import AutoDelete from '@mui/icons-material/AutoDelete'; -import KeyboardDoubleArrowUpIcon from '@mui/icons-material/KeyboardDoubleArrowUp'; import { IconButton, Menu, @@ -17,6 +16,8 @@ import { import { UserInput } from '@chainlit/react-client'; import { grey } from '@chainlit/react-components/theme'; +import ChevronUpIcon from 'assets/chevronUp'; + import { inputHistoryState } from 'state/userInputHistory'; interface Props { @@ -247,7 +248,7 @@ export default function InputHistoryButton({ disabled, onClick }: Props) { onClick={() => toggleChatHistoryMenu(!inputHistory.open)} ref={ref} > - + diff --git a/frontend/src/components/organisms/header.tsx b/frontend/src/components/organisms/header.tsx index a974093910..5d0b9bd929 100644 --- a/frontend/src/components/organisms/header.tsx +++ b/frontend/src/components/organisms/header.tsx @@ -156,7 +156,7 @@ const Header = memo( borderBottomColor: (theme) => theme.palette.divider }} > - + {!matches ? : null}