docs: set max width in assistant (#11231)
* docs: set max width in assistant * allow scrolling while showing answer
This commit is contained in:
@@ -34,7 +34,7 @@ export const AiAssistantThreadItem = ({ item }: AiAssistantThreadItemProps) => {
|
|||||||
"txt-small text-medusa-fg-base",
|
"txt-small text-medusa-fg-base",
|
||||||
item.type === "question" && [
|
item.type === "question" && [
|
||||||
"rounded-docs_xl bg-medusa-tag-neutral-bg",
|
"rounded-docs_xl bg-medusa-tag-neutral-bg",
|
||||||
"px-docs_0.75 py-docs_0.5 max-w-full",
|
"px-docs_0.75 py-docs_0.5 max-w-full md:max-w-[400px]",
|
||||||
],
|
],
|
||||||
item.type !== "question" && "flex-1",
|
item.type !== "question" && "flex-1",
|
||||||
item.type === "answer" && "text-pretty flex-1 max-w-[calc(100%-20px)]"
|
item.type === "answer" && "text-pretty flex-1 max-w-[calc(100%-20px)]"
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const MainNavVersion = () => {
|
|||||||
>
|
>
|
||||||
<Tooltip html="View the release notes<br/>on GitHub">
|
<Tooltip html="View the release notes<br/>on GitHub">
|
||||||
<span
|
<span
|
||||||
className="relative text-compact-small-plus"
|
className="relative text-compact-small-plus block"
|
||||||
onMouseOut={afterHover}
|
onMouseOut={afterHover}
|
||||||
>
|
>
|
||||||
<span className="flex justify-center items-center">
|
<span className="flex justify-center items-center">
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ export const AiAssistantChatProvider = ({
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [preventAutoScroll, setPreventAutoScroll] = useState(false)
|
||||||
const { getAnswer } = useAiAssistant()
|
const { getAnswer } = useAiAssistant()
|
||||||
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)
|
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null)
|
||||||
const contentRef = useRef<HTMLDivElement>(null)
|
const contentRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -107,6 +108,7 @@ export const AiAssistantChatProvider = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
setPreventAutoScroll(false)
|
||||||
setAnswer("")
|
setAnswer("")
|
||||||
setThread((prevThread) => [
|
setThread((prevThread) => [
|
||||||
...prevThread,
|
...prevThread,
|
||||||
@@ -160,6 +162,9 @@ export const AiAssistantChatProvider = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
|
if (preventAutoScroll) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const parent = contentRef.current?.parentElement as HTMLElement
|
const parent = contentRef.current?.parentElement as HTMLElement
|
||||||
|
|
||||||
parent.scrollTop = parent.scrollHeight
|
parent.scrollTop = parent.scrollHeight
|
||||||
@@ -311,6 +316,43 @@ export const AiAssistantChatProvider = ({
|
|||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const handleUserScroll = useCallback(() => {
|
||||||
|
if (!question.length || preventAutoScroll) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setPreventAutoScroll(true)
|
||||||
|
}, [question, preventAutoScroll])
|
||||||
|
|
||||||
|
const handleUserScrollEnd = useCallback(() => {
|
||||||
|
if (preventAutoScroll) {
|
||||||
|
setPreventAutoScroll(false)
|
||||||
|
}
|
||||||
|
}, [preventAutoScroll])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!contentRef.current?.parentElement) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
contentRef.current.parentElement.addEventListener("wheel", handleUserScroll)
|
||||||
|
contentRef.current.parentElement.addEventListener(
|
||||||
|
"touchmove",
|
||||||
|
handleUserScroll
|
||||||
|
)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
contentRef.current?.parentElement?.removeEventListener(
|
||||||
|
"wheel",
|
||||||
|
handleUserScroll
|
||||||
|
)
|
||||||
|
contentRef.current?.parentElement?.removeEventListener(
|
||||||
|
"touchmove",
|
||||||
|
handleUserScroll
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [contentRef.current, handleUserScroll])
|
||||||
|
|
||||||
const getThreadItems = useCallback(() => {
|
const getThreadItems = useCallback(() => {
|
||||||
return sortThread(thread)
|
return sortThread(thread)
|
||||||
}, [thread])
|
}, [thread])
|
||||||
|
|||||||
Reference in New Issue
Block a user