import { FC, useMemo } from 'react' import { MainDocument } from '../../../../../types/project-settings' import { Ranges } from '../context/ranges-context' import { ReviewPanelComment } from './review-panel-comment' import { ReviewPanelChange } from './review-panel-change' import { isDeleteChange, isInsertChange } from '@/utils/operations' import { Change, DeleteOperation, EditOperation, } from '../../../../../types/change' import { canAggregate } from '../utils/can-aggregate' import { Button } from 'react-bootstrap' import MaterialIcon from '@/shared/components/material-icon' import useOverviewFileCollapsed from '../hooks/use-overview-file-collapsed' import { useThreadsContext } from '../context/threads-context' export const ReviewPanelOverviewFile: FC<{ doc: MainDocument ranges: Ranges }> = ({ doc, ranges }) => { const { collapsed, toggleCollapsed } = useOverviewFileCollapsed(doc.doc.id) const threads = useThreadsContext() const { aggregates, changes } = useMemo(() => { const changes: Change[] = [] const aggregates: Map> = new Map() let precedingChange: Change | null = null for (const change of ranges.changes) { if ( precedingChange && isInsertChange(precedingChange) && isDeleteChange(change) && canAggregate(change, precedingChange) ) { aggregates.set(precedingChange.id, change) } else { changes.push(change) } precedingChange = change } return { aggregates, changes } }, [ranges]) const unresolvedComments = useMemo(() => { return ranges.comments.filter(comment => { const thread = threads?.[comment.op.t] return thread && thread.messages.length > 0 && !thread.resolved }) }, [ranges.comments, threads]) const numEntries = changes.length + unresolvedComments.length if (numEntries === 0) { return null } return ( <>
{!collapsed && (
{changes.map(change => ( ))} {unresolvedComments.map(comment => ( ))}
)}
) }