From 7b53e1c54bb1af89c5680558c028f1c60456078f Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Mon, 26 Feb 2024 20:10:00 +0530 Subject: [PATCH] UI enhancement, scroll fix --- .../src/components/DocsGPTWidget.tsx | 53 ++++++++++--------- extensions/react-widget/tailwind.config.js | 7 +++ 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/extensions/react-widget/src/components/DocsGPTWidget.tsx b/extensions/react-widget/src/components/DocsGPTWidget.tsx index 2c779df6..264623e1 100644 --- a/extensions/react-widget/src/components/DocsGPTWidget.tsx +++ b/extensions/react-widget/src/components/DocsGPTWidget.tsx @@ -1,6 +1,5 @@ "use client"; import { Fragment, useEffect, useRef, useState } from 'react' -import ReactMarkdown from 'react-markdown'; import { PaperPlaneIcon, RocketIcon, ExclamationTriangleIcon } from '@radix-ui/react-icons'; import { Input } from './ui/input'; import { Button } from './ui/button'; @@ -35,16 +34,21 @@ export const DocsGPTWidget = ({ apiHost = 'https://gptcloud.arc53.com', selectDo const [status, setStatus] = useState('idle'); const [queries, setQueries] = useState([]) const [conversationId, setConversationId] = useState(null) - //const selectDocs = 'local/1706.03762.pdf/' + const scrollRef = useRef(null); - const scrollIntoView = () => { - scrollRef.current?.scrollIntoView({ - behavior: 'smooth', - block: 'start', - }); + const scrollToBottom = (element: Element | null) => { + if (!element) return; + if (element?.children.length === 0) { + element?.scrollIntoView({ + behavior: 'smooth', + block: 'start', + }); + } + const lastChild = element?.children?.[element.children.length - 1] + lastChild && scrollToBottom(lastChild) }; useEffect(() => { - scrollIntoView(); + scrollToBottom(scrollRef.current); }, [queries.length, queries[queries.length - 1]?.response]); useEffect(() => { @@ -101,10 +105,9 @@ export const DocsGPTWidget = ({ apiHost = 'https://gptcloud.arc53.com', selectDo } - return ( <> -
+
setChatState(ChatStates.Init)} className={`${chatState !== 'minimized' ? 'hidden' : ''} cursor-pointer`}>
@@ -130,10 +133,8 @@ export const DocsGPTWidget = ({ apiHost = 'https://gptcloud.arc53.com', selectDo
- -

Get AI assistance

-

DocsGPT's AI Chatbot is here to help

- +

Get AI assistance

+

DocsGPT's AI Chatbot is here to help

@@ -145,35 +146,39 @@ export const DocsGPTWidget = ({ apiHost = 'https://gptcloud.arc53.com', selectDo {(chatState === 'typing' || chatState === 'answer' || chatState === 'processing') && (
- + { queries.length > 0 ? queries?.map((query, index) => { return ( { query.prompt &&
-

+

{query.prompt}

} { - query.response ?
-

- -

+ query.response ?
+
+ +
- :
+ :
{ - query.error ? + query.error ? Network Error Something went wrong ! - :
- add loader here + :
+

+ . + . + . +

}
diff --git a/extensions/react-widget/tailwind.config.js b/extensions/react-widget/tailwind.config.js index 7cb7e37a..92c034c7 100644 --- a/extensions/react-widget/tailwind.config.js +++ b/extensions/react-widget/tailwind.config.js @@ -71,6 +71,13 @@ module.exports = { "accordion-down": "accordion-down 0.2s ease-out", "accordion-up": "accordion-up 0.2s ease-out", }, + fontFamily: { + sans: [ + '"Segoe UI"', + 'Roboto', + 'sans-serif', + ], + } }, }, plugins: [require("tailwindcss-animate")],