mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 10:50:46 -05:00
9416e69647
Implement redesigned resolved threads popover GitOrigin-RevId: 4e462eb26a2f2f3194fca89c39d5f9d08ea2e33c
35 lines
1.1 KiB
TypeScript
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 }
|
|
}
|