Files
Verso/services/web/frontend/js/features/ide-react/hooks/use-convert-doc.ts
T
claude bc131f6440
Build and Deploy Verso / deploy (push) Successful in 15m23s
fix: convert items show for unselected files; add success toast
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>
2026-06-17 21:18:24 +00:00

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 }
}