From 4e7d98e99a0ae01dcd6e2451acd6948d088373ae Mon Sep 17 00:00:00 2001 From: bang9 Date: Fri, 6 Sep 2024 13:06:36 +0900 Subject: [PATCH] chore: add file viewer --- packages/uikit | 2 +- src/components/BotMessageWithBodyInput.tsx | 5 ++- src/components/BotProfileImage.tsx | 10 ++++-- src/components/CustomMessage.tsx | 6 ++-- .../CustomTypingIndicatorBubble.tsx | 10 +----- src/components/FileMessage.tsx | 14 ++------ src/components/chat/ui/ChatHeader.tsx | 3 +- src/components/chat/ui/ChatInput.tsx | 1 + .../messages/OutgoingFileMessage.tsx | 33 ++++++++++++++++--- src/components/ui/FileViewer.tsx | 21 ++++++++++++ 10 files changed, 68 insertions(+), 37 deletions(-) create mode 100644 src/components/ui/FileViewer.tsx diff --git a/packages/uikit b/packages/uikit index 4e7b51d87..52464b565 160000 --- a/packages/uikit +++ b/packages/uikit @@ -1 +1 @@ -Subproject commit 4e7b51d878bd77869782c755ddf595197d42720f +Subproject commit 52464b5652471c0e7522d2d851386d69111cef26 diff --git a/src/components/BotMessageWithBodyInput.tsx b/src/components/BotMessageWithBodyInput.tsx index e8cd6b90f..6b72aa6a3 100644 --- a/src/components/BotMessageWithBodyInput.tsx +++ b/src/components/BotMessageWithBodyInput.tsx @@ -63,15 +63,14 @@ export default function BotMessageWithBodyInput(props: Props) { const nonChainedMessage = chainTop == null && chainBottom == null; const displaySender = nonChainedMessage || chainTop; const displayProfileImage = nonChainedMessage || chainBottom; - const { profileUrl, nickname } = botStudioEditProps?.botInfo ?? {}; - const botProfileUrl = profileUrl ?? botUser?.profileUrl; + const { nickname } = botStudioEditProps?.botInfo ?? {}; const botNickname = nickname ?? botUser?.nickname; return ( {displayProfileImage ? (
- +
) : ( diff --git a/src/components/BotProfileImage.tsx b/src/components/BotProfileImage.tsx index 7f8a282cf..8eb53ca42 100644 --- a/src/components/BotProfileImage.tsx +++ b/src/components/BotProfileImage.tsx @@ -1,7 +1,9 @@ import { styled } from '@linaria/react'; import { useTheme } from 'styled-components'; +import { useChatContext } from './chat/context/ChatProvider'; import { getColorBasedOnSaturation } from '../colors'; +import { useConstantState } from '../context/ConstantContext'; import BotProfileIcon from '../icons/bot-profile-image-small.svg'; const Container = styled.span<{ backgroundColor: string; size: number }>` @@ -23,13 +25,17 @@ const Icon = styled(BotProfileIcon)<{ fill: string }>` `; type Props = { - profileUrl?: string; size: number; }; -function BotProfileImage({ size, profileUrl }: Props) { +function BotProfileImage({ size }: Props) { const theme = useTheme(); + const { botStudioEditProps } = useConstantState(); + const { botUser } = useChatContext(); + const { botInfo } = botStudioEditProps ?? {}; + const profileUrl = botInfo?.profileUrl ?? botUser?.profileUrl; + if (profileUrl) { return {'bot; } diff --git a/src/components/CustomMessage.tsx b/src/components/CustomMessage.tsx index 2ad69ccbb..f0b3972b5 100644 --- a/src/components/CustomMessage.tsx +++ b/src/components/CustomMessage.tsx @@ -32,12 +32,10 @@ type Props = { export default function CustomMessage(props: Props) { const { botUser } = useChatContext(); const { message, activeSpinnerId } = props; - const { replacementTextList, enableEmojiFeedback, botStudioEditProps = {} } = useConstantState(); + const { replacementTextList, enableEmojiFeedback } = useConstantState(); const { userId: currentUserId } = useWidgetSession(); - const { botInfo } = botStudioEditProps; const botUserId = botUser?.userId; - const botProfileUrl = botInfo?.profileUrl ?? botUser?.profileUrl ?? ''; const isWaitingForBotReply = activeSpinnerId === message.messageId && !!botUser; const shouldRenderFeedback = () => { @@ -103,7 +101,7 @@ export default function CustomMessage(props: Props) { } + bodyComponent={} createdAt={message.createdAt} messageFeedback={renderFeedbackButtons()} /> diff --git a/src/components/CustomTypingIndicatorBubble.tsx b/src/components/CustomTypingIndicatorBubble.tsx index c3c36e74f..ca910cf58 100644 --- a/src/components/CustomTypingIndicatorBubble.tsx +++ b/src/components/CustomTypingIndicatorBubble.tsx @@ -1,18 +1,10 @@ import BotProfileImage from './BotProfileImage'; -import { useChatContext } from './chat/context/ChatProvider'; -import { useConstantState } from '../context/ConstantContext'; import { TypingBubble } from '../foundation/components/TypingBubble'; function CustomTypingIndicatorBubble() { - const { botStudioEditProps = {} } = useConstantState(); - const { botUser } = useChatContext(); - - const botInfo = botStudioEditProps.botInfo; - const botProfileUrl = botInfo?.profileUrl ?? botUser?.profileUrl; - return (
- +
); diff --git a/src/components/FileMessage.tsx b/src/components/FileMessage.tsx index 85be3fc12..bb7457e95 100644 --- a/src/components/FileMessage.tsx +++ b/src/components/FileMessage.tsx @@ -2,19 +2,17 @@ import '../css/index.css'; import { FileMessage as ChatFileMessage } from '@sendbird/chat/message'; import { useState } from 'react'; -import FileViewer from '@uikit/modules/GroupChannel/components/FileViewer'; import { isImageMessage, isVideoMessage } from '@uikit/utils'; -import BotProfileImage from './BotProfileImage'; import { useChatContext } from './chat/context/ChatProvider'; +import { FileViewer } from './ui/FileViewer'; type Props = { message: ChatFileMessage; - profileUrl: string; }; export default function FileMessage(props: Props) { - const { message, profileUrl } = props; + const { message } = props; const { scrollSource } = useChatContext(); const [showFileViewer, setShowFileViewer] = useState(false); @@ -42,13 +40,7 @@ export default function FileMessage(props: Props) { onClick={() => setShowFileViewer(true)} /> )} - {showFileViewer && ( - setShowFileViewer(false)} - profile={} - /> - )} + {showFileViewer && setShowFileViewer(false)} />} ); } diff --git a/src/components/chat/ui/ChatHeader.tsx b/src/components/chat/ui/ChatHeader.tsx index 515a7482f..faaf1b836 100644 --- a/src/components/chat/ui/ChatHeader.tsx +++ b/src/components/chat/ui/ChatHeader.tsx @@ -25,7 +25,6 @@ export const ChatHeader = ({ fullscreen }: Props) => { const { botInfo } = botStudioEditProps ?? {}; const botNickname = botInfo?.nickname ?? botUser?.nickname; - const profileUrl = botInfo?.profileUrl ?? botUser?.profileUrl; const buttonSize = isMobileView ? 24 : 16; const isExpandableMode = !fullscreen && !isMobileView; @@ -43,7 +42,7 @@ export const ChatHeader = ({ fullscreen }: Props) => { return (
- +