overleaf/services/web/frontend/js/features/review-panel-new/hooks/use-project-ranges.ts
David 9416e69647 Merge pull request #19985 from overleaf/dp-resolved-threads
Implement redesigned resolved threads popover

GitOrigin-RevId: 4e462eb26a2f2f3194fca89c39d5f9d08ea2e33c
2024-08-20 08:04:35 +00:00

35 lines
1.1 KiB
TypeScript

import { useEffect, useState } from 'react'
import { Ranges } from '../context/ranges-context'
import { useProjectContext } from '@/shared/context/project-context'
import { getJSON } from '@/infrastructure/fetch-json'
export default function useProjectRanges() {
const { _id: projectId } = useProjectContext()
const [error, setError] = useState<Error>()
const [projectRanges, setProjectRanges] = useState<Map<string, Ranges>>()
const [loading, setLoading] = useState(true)
useEffect(() => {
setLoading(true)
getJSON<{ id: string; ranges: Ranges }[]>(`/project/${projectId}/ranges`)
.then(data => {
setProjectRanges(
new Map(
data.map(item => [
item.id,
{
docId: item.id,
changes: item.ranges.changes ?? [],
comments: item.ranges.comments ?? [],
total: 0, // TODO
},
])
)
)
})
.catch(error => setError(error))
.finally(() => setLoading(false))
}, [projectId])
return { projectRanges, error, loading }
}