From 5f4f4a8ab9786ea0b64de14cb0de2215aa0ec340 Mon Sep 17 00:00:00 2001 From: Siddhant Rai Date: Mon, 19 Aug 2024 18:14:49 +0530 Subject: [PATCH] fix: skeleton shown for 0 chunks and 'None' doc --- .../src/conversation/ConversationBubble.tsx | 170 +++++++++--------- 1 file changed, 89 insertions(+), 81 deletions(-) diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx index 6cb97f40..6ad877c3 100644 --- a/frontend/src/conversation/ConversationBubble.tsx +++ b/frontend/src/conversation/ConversationBubble.tsx @@ -15,6 +15,10 @@ import Sources from '../assets/sources.svg'; import Avatar from '../components/Avatar'; import CopyButton from '../components/CopyButton'; import Sidebar from '../components/Sidebar'; +import { + selectChunks, + selectSelectedDocs, +} from '../preferences/preferenceSlice'; import classes from './ConversationBubble.module.css'; import { FEEDBACK, MESSAGE_TYPE } from './conversationModels'; @@ -35,6 +39,8 @@ const ConversationBubble = forwardRef< { message, type, className, feedback, handleFeedback, sources, retryBtn }, ref, ) { + const chunks = useSelector(selectChunks); + const selectedDocs = useSelector(selectSelectedDocs); const [isLikeHovered, setIsLikeHovered] = useState(false); const [isDislikeHovered, setIsDislikeHovered] = useState(false); const [isLikeClicked, setIsLikeClicked] = useState(false); @@ -63,9 +69,9 @@ const ConversationBubble = forwardRef< {DisableSourceFE || type === 'ERROR' || sources?.length === 0 || - sources?.some( - (source) => source.source === 'None', - ) ? null : !sources ? ( + sources?.some((source) => source.source === 'None') ? null : !sources && + chunks !== '0' && + selectedDocs ? (
) : ( -
-
- - } - /> -

Sources

-
-
-
- {sources?.slice(0, 3)?.map((source, index) => ( -
-
setActiveTooltip(index)} - onMouseOut={() => setActiveTooltip(null)} - > -

- {source.text} -

+ sources && ( +
+
+ + } + /> +

Sources

+
+
+
+ {sources?.slice(0, 3)?.map((source, index) => ( +
- source.source && source.source !== 'local' - ? window.open( - source.source, - '_blank', - 'noopener, noreferrer', - ) - : null - } - > - Document -

- {source.source && source.source !== 'local' - ? source.source - : source.title} -

-
-
- {activeTooltip === index && ( -
setActiveTooltip(index)} onMouseOut={() => setActiveTooltip(null)} > -

+

{source.text}

+
+ source.source && source.source !== 'local' + ? window.open( + source.source, + '_blank', + 'noopener, noreferrer', + ) + : null + } + > + Document +

+ {source.source && source.source !== 'local' + ? source.source + : source.title} +

+
- )} -
- ))} - {(sources?.length ?? 0) > 3 && ( -
setIsSidebarOpen(true)} - > -

{`View ${ - sources?.length ? sources.length - 3 : 0 - } more`}

-
- )} + {activeTooltip === index && ( +
setActiveTooltip(index)} + onMouseOut={() => setActiveTooltip(null)} + > +

+ {source.text} +

+
+ )} +
+ ))} + {(sources?.length ?? 0) > 3 && ( +
setIsSidebarOpen(true)} + > +

{`View ${ + sources?.length ? sources.length - 3 : 0 + } more`}

+
+ )} +
-
+ ) )}