Fix file tree refresh after convert and compiler sync on set-as-main
Build and Deploy Verso / deploy (push) Successful in 14m4s
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>
This commit is contained in:
@@ -264,7 +264,7 @@ async function convertDocInProject(req, res) {
|
||||
req.ip
|
||||
)
|
||||
|
||||
res.json({ docId: resultDocId, name: resultName })
|
||||
res.json({ docId: resultDocId, name: resultName, parentFolderId: parentFolderId.toString(), isNew: !existingDoc })
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
+22
-5
@@ -2,6 +2,8 @@ import { useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
||||
import { useProjectContext } from '@/shared/context/project-context'
|
||||
import { postJSON } from '@/infrastructure/fetch-json'
|
||||
import type { ProjectCompiler } from '@ol-types/project-settings'
|
||||
|
||||
import {
|
||||
DropdownDivider,
|
||||
@@ -15,7 +17,16 @@ import { findInTree } from '../../util/find-in-tree'
|
||||
import useConvertDoc from '@/features/ide-react/hooks/use-convert-doc'
|
||||
import getMeta from '@/utils/meta'
|
||||
import { isValidTeXFile } from '@/main/is-valid-tex-file'
|
||||
import { syncRootDocId } from '../../util/sync-mutation'
|
||||
|
||||
const COMPILER_BY_EXT: Record<string, ProjectCompiler> = {
|
||||
tex: 'pdflatex',
|
||||
rtex: 'pdflatex',
|
||||
ltx: 'pdflatex',
|
||||
rnw: 'pdflatex',
|
||||
typ: 'typst',
|
||||
qmd: 'quarto',
|
||||
rmd: 'quarto',
|
||||
}
|
||||
|
||||
function FileTreeItemMenuItems() {
|
||||
const { t } = useTranslation()
|
||||
@@ -74,10 +85,16 @@ function FileTreeItemMenuItems() {
|
||||
isValidTeXFile(convertEntityName)
|
||||
|
||||
const handleSetAsMain = useCallback(async () => {
|
||||
if (!convertEntityId) return
|
||||
await syncRootDocId(projectId, convertEntityId)
|
||||
updateProject({ rootDocId: convertEntityId })
|
||||
}, [convertEntityId, projectId, updateProject])
|
||||
if (!convertEntityId || !convertEntityName) return
|
||||
const ext = convertEntityName.split('.').pop()?.toLowerCase() ?? ''
|
||||
const newCompiler = COMPILER_BY_EXT[ext]
|
||||
const body: Record<string, string> = { rootDocId: convertEntityId }
|
||||
if (newCompiler && newCompiler !== project?.compiler) body.compiler = newCompiler
|
||||
await postJSON(`/project/${projectId}/settings`, { body })
|
||||
const update: Record<string, string> = { rootDocId: convertEntityId }
|
||||
if (newCompiler) update.compiler = newCompiler
|
||||
updateProject(update)
|
||||
}, [convertEntityId, convertEntityName, project, projectId, updateProject])
|
||||
|
||||
const { convert: convertToTypst } = useConvertDoc('typst', convertEntityId)
|
||||
const { convert: convertToLatex } = useConvertDoc('latex', convertEntityId)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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,
|
||||
@@ -12,6 +13,7 @@ export default function useConvertDoc(
|
||||
docId: string | null
|
||||
) {
|
||||
const { projectId } = useProjectContext()
|
||||
const { dispatchCreateDoc } = useFileTreeData()
|
||||
const [converting, setConverting] = useState(false)
|
||||
|
||||
const convert = useCallback(async () => {
|
||||
@@ -19,17 +21,24 @@ export default function useConvertDoc(
|
||||
setConverting(true)
|
||||
hideExportDocumentError()
|
||||
try {
|
||||
await postJSON(`/project/${projectId}/doc/${docId}/convert/${type}`, {
|
||||
body: {},
|
||||
})
|
||||
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])
|
||||
}, [projectId, docId, type, dispatchCreateDoc])
|
||||
|
||||
return { convert, converting }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user