diff --git a/extensions/react-widget/src/components/DocsGPTWidget.tsx b/extensions/react-widget/src/components/DocsGPTWidget.tsx index 7a43cb7b..557aa9a0 100644 --- a/extensions/react-widget/src/components/DocsGPTWidget.tsx +++ b/extensions/react-widget/src/components/DocsGPTWidget.tsx @@ -67,16 +67,15 @@ const WidgetContainer = styled.div<{ modal?: boolean, isOpen?: boolean }>` bottom: ${props => props.modal ? '50%' : '10px'}; z-index: 1001; transform-origin:100% 100%; + display: block; &.modal{ transform : translate(50%,50%); } &.open { animation: createBox 250ms cubic-bezier(0.25, 0.1, 0.25, 1) forwards; - display: block; } &.close { animation: closeBox 250ms cubic-bezier(0.25, 0.1, 0.25, 1) forwards; - display: none; } align-items: center; text-align: left; @@ -494,24 +493,20 @@ export const DocsGPTWidget = (props: WidgetProps) => { const [open, setOpen] = React.useState(defaultOpen); const [isAnimatingButton, setIsAnimatingButton] = React.useState(false); const [isFloatingButtonVisible, setIsFloatingButtonVisible] = React.useState(true); - const widgetRef = useRef(null) + React.useEffect(() => { + if(isFloatingButtonVisible) + setTimeout(() => setIsAnimatingButton(false), 400); + }, [isFloatingButtonVisible]) const handleClose = () => { + setIsFloatingButtonVisible(true); + setIsAnimatingButton(true); setOpen(false); - setTimeout(() => { - if (widgetRef.current) - widgetRef.current.style.display = "none"; - setIsFloatingButtonVisible(true); - setIsAnimatingButton(true); - setTimeout(() => setIsAnimatingButton(false), 200); - }, 250) }; const handleOpen = () => { setOpen(true); setIsFloatingButtonVisible(false); - if (widgetRef.current) - widgetRef.current.style.display = 'block' } return ( <> @@ -519,7 +514,7 @@ export const DocsGPTWidget = (props: WidgetProps) => { {buttonText} - + ) } @@ -534,14 +529,13 @@ export const WidgetCore = ({ size = 'small', theme = 'dark', collectFeedback = true, - widgetRef = null, isOpen = false, prefilledQuery = "", handleClose }: WidgetCoreProps) => { - const [prompt, setPrompt] = React.useState(prefilledQuery); - console.log("propmpt",prompt); - + const [prompt, setPrompt] = React.useState(""); + console.log("propmpt", prompt); + const [mounted, setMounted] = React.useState(false); const [status, setStatus] = React.useState('idle'); const [queries, setQueries] = React.useState([]); const [conversationId, setConversationId] = React.useState(null); @@ -551,6 +545,22 @@ export const WidgetCore = ({ const endMessageRef = React.useRef(null); const md = new MarkdownIt(); + React.useEffect(() => { + if (isOpen) { + setMounted(true); // Mount the component + setPrompt(prefilledQuery) + } else { + // Wait for animations before unmounting + const timeout = setTimeout(() => { + setMounted(false) + console.log("Unmounted syccess") + }, 250); + return () => clearTimeout(timeout); + } + }, [isOpen]); + + + const handleUserInterrupt = () => { (status === 'loading') && setEventInterrupt(true); } @@ -663,114 +673,114 @@ export const WidgetCore = ({ typeof size === 'object' && 'custom' in size ? sizesConfig.getCustom(size.custom) : sizesConfig[size]; + if (!mounted) return null; return ( {isOpen && size === 'large' && } - { - isOpen && ( - - -
- - - -
- docs-gpt - - {title} - {description} - -
-
- - { - queries.length > 0 ? queries?.map((query, index) => { - return ( - - { - query.prompt && - - {query.prompt} - - - } - { - query.response ? { isBubbleHovered.current = true }} type='ANSWER'> - - - + {( + + +
+ + + +
+ docs-gpt + + {title} + {description} + +
+
+ + { + queries.length > 0 ? queries?.map((query, index) => { + return ( + + { + query.prompt && + + {query.prompt} + + + } + { + query.response ? { isBubbleHovered.current = true }} type='ANSWER'> + + + - {collectFeedback && - - handleFeedback("LIKE", index)} /> - handleFeedback("DISLIKE", index)} /> - } - - :
- { - query.error ? + {collectFeedback && + + handleFeedback("LIKE", index)} /> + handleFeedback("DISLIKE", index)} /> + } + + :
+ { + query.error ? - -
-
Network Error
- {query.error} -
-
- : - - . - . - . - - - } -
- } - ) - }) - : - } - -
- - setPrompt(event.target.value)} - type='text' placeholder="Ask your question" /> - - - - - - Powered by  - DocsGPT - -
- - - ) + +
+
Network Error
+ {query.error} +
+
+ : + + . + . + . + + + } +
+ } +
) + }) + : + } +
+
+ + setPrompt(event.target.value)} + type='text' placeholder="Ask your question" /> + + + + + + Powered by  + DocsGPT + +
+
+
+ ) }
) diff --git a/extensions/react-widget/src/components/SearchBar.tsx b/extensions/react-widget/src/components/SearchBar.tsx index 2589cb2f..5486871b 100644 --- a/extensions/react-widget/src/components/SearchBar.tsx +++ b/extensions/react-widget/src/components/SearchBar.tsx @@ -45,11 +45,12 @@ const TextField = styled.input` display: inline; color: ${props => props.theme.primary.text}; outline: none; - border: 2px solid transparent; + border: none; background-color: ${props => props.theme.secondary.bg}; + width: 240px; &:focus { - border:2px solid #007ee6; - box-shadow: 0px 0px 2px skyblue; + outline: none; + box-shadow: 0px 0px 0px 2px rgba(0, 109, 199); background-color: ${props => props.theme.primary.bg}; } ` @@ -84,9 +85,7 @@ const Title = styled.h3` font-weight: 600; text-transform: uppercase; border-bottom: 1px solid ${(props) => props.theme.secondary.text}; - ` - const Content = styled.div` font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; ` @@ -141,7 +140,7 @@ font-size: 12px; export const SearchBar = ({ apiKey = "79bcbf0e-3dd1-4ac3-b893-e41b3d40ec8d", apiHost = "http://127.0.0.1:7091", - theme = "dark", + theme = "light", placeholder = "Search or Ask AI" }: SearchBarProps) => { const [input, setInput] = React.useState("") @@ -157,7 +156,7 @@ export const SearchBar = ({ : setResults([]) }, [input]) - + const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter') { setIsWidgetOpen(true); @@ -196,15 +195,14 @@ export const SearchBar = ({ ) } - {isWidgetOpen && } - + /> ) diff --git a/frontend/.env.development b/frontend/.env.development index 7a87f762..9569966a 100644 --- a/frontend/.env.development +++ b/frontend/.env.development @@ -1,3 +1,3 @@ # Please put appropriate value -VITE_API_HOST=http://0.0.0.0:7091 +VITE_API_HOST=http://127.0.0.1:7091 VITE_API_STREAMING=true \ No newline at end of file