1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-17 12:09:08 +00:00

Merge pull request from overleaf/dk-fix-positionItems

Change focused item index to be per docId in new review panel

GitOrigin-RevId: af4b91cdc7128302a75f25d11c2afc5a2861abdd
This commit is contained in:
David 2024-09-19 11:08:13 +01:00 committed by Copybot
parent 8685d87920
commit 8a0bed71e1
2 changed files with 19 additions and 10 deletions
services/web/frontend/js/features/review-panel-new

View file

@ -45,20 +45,26 @@ const ReviewPanelCurrentFile: FC = () => {
const [aggregatedRanges, setAggregatedRanges] = useState<AggregatedRanges>()
const containerRef = useRef<HTMLDivElement | null>(null)
const previousFocusedItem = useRef(0)
const previousFocusedItem = useRef(new Map<string, number>())
const updatePositions = useCallback(() => {
if (containerRef.current) {
const extents = positionItems(
const docId = ranges?.docId
if (containerRef.current && docId) {
const positioningRes = positionItems(
containerRef.current,
previousFocusedItem.current
previousFocusedItem.current.get(docId) || 0,
docId
)
if (extents) {
previousFocusedItem.current = extents.activeItemIndex
if (positioningRes) {
previousFocusedItem.current.set(
positioningRes.docId,
positioningRes.activeItemIndex
)
}
}
}, [])
}, [ranges?.docId])
useEffect(() => {
const timer = window.setTimeout(() => {

View file

@ -4,7 +4,11 @@ const COLLAPSED_HEADER_HEIGHT = 75
const OFFSET_FOR_ENTRIES_ABOVE = 70
export const positionItems = debounce(
(element: HTMLDivElement, previousFocusedItemIndex: number) => {
(
element: HTMLDivElement,
previousFocusedItemIndex: number,
docId: string
) => {
const items = Array.from(
element.querySelectorAll<HTMLDivElement>('.review-panel-entry')
)
@ -80,9 +84,8 @@ export const positionItems = debounce(
}
return {
docId,
activeItemIndex,
min: topLimit,
max: bottomLimit,
}
},
100,