mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
4b4ed6147c
[misc] better error msg for failed compiles when linking project files GitOrigin-RevId: cac3d9e5cf25918dc8f5e259d106c145235c15c1
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import { useEffect, useState } from 'react'
|
|
import { postJSON } from '../../../infrastructure/fetch-json'
|
|
import { fileCollator } from '../util/file-collator'
|
|
import useAbortController from '../../../shared/hooks/use-abort-controller'
|
|
|
|
const alphabetical = (a, b) => fileCollator.compare(a.path, b.path)
|
|
|
|
export function useProjectOutputFiles(projectId) {
|
|
const [loading, setLoading] = useState(false)
|
|
const [data, setData] = useState(null)
|
|
const [error, setError] = useState(false)
|
|
|
|
const { signal } = useAbortController()
|
|
|
|
useEffect(() => {
|
|
if (projectId) {
|
|
setLoading(true)
|
|
setError(false)
|
|
setData(null)
|
|
|
|
postJSON(`/project/${projectId}/compile`, {
|
|
body: {
|
|
check: 'silent',
|
|
draft: false,
|
|
incrementalCompilesEnabled: false,
|
|
},
|
|
signal,
|
|
})
|
|
.then(data => {
|
|
if (data.status === 'success') {
|
|
const filteredFiles = data.outputFiles.filter(file =>
|
|
file.path.match(/.*\.(pdf|png|jpeg|jpg|gif)/)
|
|
)
|
|
|
|
setData(filteredFiles.sort(alphabetical))
|
|
} else {
|
|
setError('linked-project-compile-error')
|
|
}
|
|
})
|
|
.catch(error => setError(error))
|
|
.finally(() => setLoading(false))
|
|
}
|
|
}, [projectId, signal])
|
|
|
|
return { loading, data, error }
|
|
}
|