1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2024-12-14 13:40:55 -05:00
overleaf/services/web/frontend/js/features/review-panel-new/components/review-panel-container.tsx
David 1c7e4ddcd2 Merge pull request from overleaf/dp-focus-entry
Refactor how ReviewPanel and TrackChangesWidget are rendered

GitOrigin-RevId: 0b206a2a70270a885befdcf2403da4e1af3aa9bf
2024-11-05 09:04:54 +00:00

36 lines
1.3 KiB
TypeScript

import ReactDOM from 'react-dom'
import { useCodeMirrorViewContext } from '../../source-editor/components/codemirror-context'
import { memo } from 'react'
import ReviewPanel from './review-panel'
import { useLayoutContext } from '@/shared/context/layout-context'
import { useRangesContext } from '../context/ranges-context'
import { useThreadsContext } from '@/features/review-panel-new/context/threads-context'
import { hasActiveRange } from '@/features/review-panel-new/utils/has-active-range'
import TrackChangesOnWidget from './track-changes-on-widget'
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
function ReviewPanelContainer() {
const view = useCodeMirrorViewContext()
const ranges = useRangesContext()
const threads = useThreadsContext()
const { reviewPanelOpen } = useLayoutContext()
const { wantTrackChanges } = useEditorManagerContext()
if (!view) {
return null
}
const hasCommentOrChange = hasActiveRange(ranges, threads)
const showPanel = reviewPanelOpen || hasCommentOrChange
const showTrackChangesWidget = wantTrackChanges && !reviewPanelOpen
return ReactDOM.createPortal(
<>
{showTrackChangesWidget && <TrackChangesOnWidget />}
{showPanel && <ReviewPanel mini={!reviewPanelOpen} />}
</>,
view.scrollDOM
)
}
export default memo(ReviewPanelContainer)