065534819c
Build and Deploy Verso / deploy (push) Successful in 14m4s
- Convert: backend now returns parentFolderId+isNew; frontend calls dispatchCreateDoc directly so the new file appears without a page refresh - Set as main: infer compiler from file extension and POST both rootDocId and compiler together; updateProject propagates the change to the editor settings dropdown and project list immediately Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { postJSON } from '@/infrastructure/fetch-json'
|
|
import { useProjectContext } from '@/shared/context/project-context'
|
|
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
|
import { useCallback, useState } from 'react'
|
|
import {
|
|
showExportDocumentError,
|
|
showExportDocumentSuccess,
|
|
hideExportDocumentError,
|
|
} from '../components/toolbar/export-document-toasts'
|
|
|
|
export default function useConvertDoc(
|
|
type: 'typst' | 'latex',
|
|
docId: string | null
|
|
) {
|
|
const { projectId } = useProjectContext()
|
|
const { dispatchCreateDoc } = useFileTreeData()
|
|
const [converting, setConverting] = useState(false)
|
|
|
|
const convert = useCallback(async () => {
|
|
if (!docId) return
|
|
setConverting(true)
|
|
hideExportDocumentError()
|
|
try {
|
|
const result = await postJSON(
|
|
`/project/${projectId}/doc/${docId}/convert/${type}`,
|
|
{ body: {} }
|
|
)
|
|
showExportDocumentSuccess(type)
|
|
if (result.isNew) {
|
|
dispatchCreateDoc(result.parentFolderId, {
|
|
_id: result.docId,
|
|
name: result.name,
|
|
})
|
|
}
|
|
} catch (err: any) {
|
|
const errorMessage = err?.data?.error
|
|
showExportDocumentError(errorMessage)
|
|
} finally {
|
|
setConverting(false)
|
|
}
|
|
}, [projectId, docId, type, dispatchCreateDoc])
|
|
|
|
return { convert, converting }
|
|
}
|