2024-08-12 05:50:54 -04:00
|
|
|
import ReactDOM from 'react-dom'
|
2024-09-27 06:31:31 -04:00
|
|
|
import { useCodeMirrorViewContext } from '../../source-editor/components/codemirror-context'
|
2024-08-12 05:50:54 -04:00
|
|
|
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-10-21 05:06:30 -04:00
|
|
|
import TrackChangesOnWidget from './track-changes-on-widget'
|
|
|
|
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
|
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-10-21 05:06:30 -04:00
|
|
|
const { wantTrackChanges } = useEditorManagerContext()
|
2024-08-12 05:50:54 -04:00
|
|
|
|
2024-08-22 05:44:22 -04:00
|
|
|
if (!view) {
|
2024-08-12 05:50:54 -04:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2024-11-04 08:30:24 -05:00
|
|
|
const hasCommentOrChange = hasActiveRange(ranges, threads)
|
|
|
|
const showPanel = reviewPanelOpen || hasCommentOrChange
|
|
|
|
const showTrackChangesWidget = wantTrackChanges && !reviewPanelOpen
|
2024-08-22 05:44:22 -04:00
|
|
|
|
2024-11-04 08:30:24 -05:00
|
|
|
return ReactDOM.createPortal(
|
|
|
|
<>
|
|
|
|
{showTrackChangesWidget && <TrackChangesOnWidget />}
|
|
|
|
{showPanel && <ReviewPanel mini={!reviewPanelOpen} />}
|
|
|
|
</>,
|
|
|
|
view.scrollDOM
|
|
|
|
)
|
2024-08-12 05:50:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(ReviewPanelContainer)
|