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
|
req.ip
|
||||||
)
|
)
|
||||||
|
|
||||||
res.json({ docId: resultDocId, name: resultName })
|
res.json({ docId: resultDocId, name: resultName, parentFolderId: parentFolderId.toString(), isNew: !existingDoc })
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
+22
-5
@@ -2,6 +2,8 @@ import { useCallback } from 'react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
||||||
import { useProjectContext } from '@/shared/context/project-context'
|
import { useProjectContext } from '@/shared/context/project-context'
|
||||||
|
import { postJSON } from '@/infrastructure/fetch-json'
|
||||||
|
import type { ProjectCompiler } from '@ol-types/project-settings'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DropdownDivider,
|
DropdownDivider,
|
||||||
@@ -15,7 +17,16 @@ import { findInTree } from '../../util/find-in-tree'
|
|||||||
import useConvertDoc from '@/features/ide-react/hooks/use-convert-doc'
|
import useConvertDoc from '@/features/ide-react/hooks/use-convert-doc'
|
||||||
import getMeta from '@/utils/meta'
|
import getMeta from '@/utils/meta'
|
||||||
import { isValidTeXFile } from '@/main/is-valid-tex-file'
|
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() {
|
function FileTreeItemMenuItems() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@@ -74,10 +85,16 @@ function FileTreeItemMenuItems() {
|
|||||||
isValidTeXFile(convertEntityName)
|
isValidTeXFile(convertEntityName)
|
||||||
|
|
||||||
const handleSetAsMain = useCallback(async () => {
|
const handleSetAsMain = useCallback(async () => {
|
||||||
if (!convertEntityId) return
|
if (!convertEntityId || !convertEntityName) return
|
||||||
await syncRootDocId(projectId, convertEntityId)
|
const ext = convertEntityName.split('.').pop()?.toLowerCase() ?? ''
|
||||||
updateProject({ rootDocId: convertEntityId })
|
const newCompiler = COMPILER_BY_EXT[ext]
|
||||||
}, [convertEntityId, projectId, updateProject])
|
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: convertToTypst } = useConvertDoc('typst', convertEntityId)
|
||||||
const { convert: convertToLatex } = useConvertDoc('latex', convertEntityId)
|
const { convert: convertToLatex } = useConvertDoc('latex', convertEntityId)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { postJSON } from '@/infrastructure/fetch-json'
|
import { postJSON } from '@/infrastructure/fetch-json'
|
||||||
import { useProjectContext } from '@/shared/context/project-context'
|
import { useProjectContext } from '@/shared/context/project-context'
|
||||||
|
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
import {
|
import {
|
||||||
showExportDocumentError,
|
showExportDocumentError,
|
||||||
@@ -12,6 +13,7 @@ export default function useConvertDoc(
|
|||||||
docId: string | null
|
docId: string | null
|
||||||
) {
|
) {
|
||||||
const { projectId } = useProjectContext()
|
const { projectId } = useProjectContext()
|
||||||
|
const { dispatchCreateDoc } = useFileTreeData()
|
||||||
const [converting, setConverting] = useState(false)
|
const [converting, setConverting] = useState(false)
|
||||||
|
|
||||||
const convert = useCallback(async () => {
|
const convert = useCallback(async () => {
|
||||||
@@ -19,17 +21,24 @@ export default function useConvertDoc(
|
|||||||
setConverting(true)
|
setConverting(true)
|
||||||
hideExportDocumentError()
|
hideExportDocumentError()
|
||||||
try {
|
try {
|
||||||
await postJSON(`/project/${projectId}/doc/${docId}/convert/${type}`, {
|
const result = await postJSON(
|
||||||
body: {},
|
`/project/${projectId}/doc/${docId}/convert/${type}`,
|
||||||
})
|
{ body: {} }
|
||||||
|
)
|
||||||
showExportDocumentSuccess(type)
|
showExportDocumentSuccess(type)
|
||||||
|
if (result.isNew) {
|
||||||
|
dispatchCreateDoc(result.parentFolderId, {
|
||||||
|
_id: result.docId,
|
||||||
|
name: result.name,
|
||||||
|
})
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const errorMessage = err?.data?.error
|
const errorMessage = err?.data?.error
|
||||||
showExportDocumentError(errorMessage)
|
showExportDocumentError(errorMessage)
|
||||||
} finally {
|
} finally {
|
||||||
setConverting(false)
|
setConverting(false)
|
||||||
}
|
}
|
||||||
}, [projectId, docId, type])
|
}, [projectId, docId, type, dispatchCreateDoc])
|
||||||
|
|
||||||
return { convert, converting }
|
return { convert, converting }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user