bc131f6440
Build and Deploy Verso / deploy (push) Successful in 15m23s
canRename required selectedEntityIds.size === 1, so right-clicking an unselected file hid the convert items even though contextMenuEntityId was correctly set. Replace canRename with !fileTreeReadOnly for the convert-specific gate, which is the actual write-access check needed. Also add showExportDocumentSuccess so the user sees the warning toast on successful conversion instead of silent nothing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1011 B
TypeScript
36 lines
1011 B
TypeScript
import { postJSON } from '@/infrastructure/fetch-json'
|
|
import { useProjectContext } from '@/shared/context/project-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 [converting, setConverting] = useState(false)
|
|
|
|
const convert = useCallback(async () => {
|
|
if (!docId) return
|
|
setConverting(true)
|
|
hideExportDocumentError()
|
|
try {
|
|
await postJSON(`/project/${projectId}/doc/${docId}/convert/${type}`, {
|
|
body: {},
|
|
})
|
|
showExportDocumentSuccess(type)
|
|
} catch (err: any) {
|
|
const errorMessage = err?.data?.error
|
|
showExportDocumentError(errorMessage)
|
|
} finally {
|
|
setConverting(false)
|
|
}
|
|
}, [projectId, docId, type])
|
|
|
|
return { convert, converting }
|
|
}
|