2023-12-05 05:19:00 -05:00
|
|
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
|
|
|
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
|
2023-12-20 06:48:24 -05:00
|
|
|
import { useCallback, useRef, useState } from 'react'
|
|
|
|
import { ImperativePanelHandle } from 'react-resizable-panels'
|
2023-12-05 05:19:00 -05:00
|
|
|
|
|
|
|
export const useChatPane = () => {
|
2023-12-08 04:37:05 -05:00
|
|
|
const { chatIsOpen: isOpen, setChatIsOpen: setIsOpen } = useLayoutContext()
|
2023-12-05 05:19:00 -05:00
|
|
|
const [resizing, setResizing] = useState(false)
|
2023-12-20 06:48:24 -05:00
|
|
|
const panelRef = useRef<ImperativePanelHandle>(null)
|
|
|
|
|
|
|
|
useCollapsiblePanel(isOpen, panelRef)
|
2023-12-05 05:19:00 -05:00
|
|
|
|
2023-12-08 04:37:05 -05:00
|
|
|
const togglePane = useCallback(() => {
|
|
|
|
setIsOpen(value => !value)
|
|
|
|
}, [setIsOpen])
|
|
|
|
|
|
|
|
const handlePaneExpand = useCallback(() => {
|
|
|
|
setIsOpen(true)
|
|
|
|
}, [setIsOpen])
|
|
|
|
|
|
|
|
const handlePaneCollapse = useCallback(() => {
|
|
|
|
setIsOpen(false)
|
|
|
|
}, [setIsOpen])
|
|
|
|
|
|
|
|
return {
|
|
|
|
isOpen,
|
2023-12-20 06:48:24 -05:00
|
|
|
panelRef,
|
2023-12-08 04:37:05 -05:00
|
|
|
resizing,
|
|
|
|
setResizing,
|
|
|
|
togglePane,
|
|
|
|
handlePaneExpand,
|
|
|
|
handlePaneCollapse,
|
|
|
|
}
|
2023-12-05 05:19:00 -05:00
|
|
|
}
|