2024-08-12 05:50:54 -04:00
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
import { useCodeMirrorViewContext } from '../../source-editor/components/codemirror-editor'
|
|
|
|
import { memo } from 'react'
|
|
|
|
import ReviewPanel from './review-panel'
|
|
|
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
|
|
|
import { useRangesContext } from '../context/ranges-context'
|
2024-08-22 05:44:22 -04:00
|
|
|
import { useThreadsContext } from '@/features/review-panel-new/context/threads-context'
|
|
|
|
import { hasActiveRange } from '@/features/review-panel-new/utils/has-active-range'
|
2024-08-12 05:50:54 -04:00
|
|
|
|
|
|
|
function ReviewPanelContainer() {
|
|
|
|
const view = useCodeMirrorViewContext()
|
|
|
|
const ranges = useRangesContext()
|
2024-08-22 05:44:22 -04:00
|
|
|
const threads = useThreadsContext()
|
2024-08-12 05:50:54 -04:00
|
|
|
const { reviewPanelOpen } = useLayoutContext()
|
|
|
|
|
2024-08-22 05:44:22 -04:00
|
|
|
if (!view) {
|
2024-08-12 05:50:54 -04:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2024-08-22 05:44:22 -04:00
|
|
|
// the full-width review panel
|
|
|
|
if (reviewPanelOpen) {
|
|
|
|
return ReactDOM.createPortal(<ReviewPanel />, view.scrollDOM)
|
|
|
|
}
|
|
|
|
|
|
|
|
// the mini review panel
|
|
|
|
if (hasActiveRange(ranges, threads)) {
|
|
|
|
return ReactDOM.createPortal(<ReviewPanel mini />, view.scrollDOM)
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
2024-08-12 05:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(ReviewPanelContainer)
|