From e37fa7cff9f755801ce36293ecf4337d1ecf927a Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Fri, 4 Oct 2024 03:17:42 -0400 Subject: [PATCH] Add see more button to model description --- .../src/components/settings/ApiOptions.tsx | 10 +- .../settings/OpenRouterModelPicker.tsx | 120 ++++++++++++++++-- 2 files changed, 115 insertions(+), 15 deletions(-) diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index aec9ca6..f5aae3d 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -574,10 +574,18 @@ export const formatPrice = (price: number) => { } export const ModelInfoView = ({ selectedModelId, modelInfo }: { selectedModelId: string; modelInfo: ModelInfo }) => { + const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false) const isGemini = Object.keys(geminiModels).includes(selectedModelId) const infoItems = [ - modelInfo.description && , + modelInfo.description && ( + + ), { const { apiConfiguration, setApiConfiguration, openRouterModels } = useExtensionState() @@ -269,16 +269,108 @@ const StyledMarkdown = styled.div` } ` -export const ModelDescriptionMarkdown = memo(({ markdown, key }: { markdown?: string; key: string }) => { - const [reactContent, setMarkdown] = useRemark() +export const ModelDescriptionMarkdown = memo( + ({ + markdown, + key, + isExpanded, + setIsExpanded, + }: { + markdown?: string + key: string + isExpanded: boolean + setIsExpanded: (isExpanded: boolean) => void + }) => { + const [reactContent, setMarkdown] = useRemark() + // const [isExpanded, setIsExpanded] = useState(false) + const [showSeeMore, setShowSeeMore] = useState(false) + const textContainerRef = useRef(null) + const textRef = useRef(null) - useEffect(() => { - setMarkdown(markdown || "") - }, [markdown, setMarkdown]) + useEffect(() => { + setMarkdown(markdown || "") + }, [markdown, setMarkdown]) - return ( - - {reactContent} - - ) -}) + useEffect(() => { + if (textRef.current && textContainerRef.current) { + const { scrollHeight } = textRef.current + const { clientHeight } = textContainerRef.current + const isOverflowing = scrollHeight > clientHeight + setShowSeeMore(isOverflowing) + // if (!isOverflowing) { + // setIsExpanded(false) + // } + } + }, [reactContent, setIsExpanded]) + + return ( + +
+
+ {reactContent} +
+ {!isExpanded && showSeeMore && ( +
+
+
setIsExpanded(true)}> + See more +
+
+ )} +
+ {/* {isExpanded && showSeeMore && ( +
setIsExpanded(false)}> + See less +
+ )} */} + + ) + } +)