|
@@ -6,14 +6,19 @@ import { File } from '../../../utils/file'
|
|
|
import { useCurrentProjectFolders } from '../../../hooks/useCurrentProjectFolders'
|
|
import { useCurrentProjectFolders } from '../../../hooks/useCurrentProjectFolders'
|
|
|
import { FileRelocator } from '../file-relocator'
|
|
import { FileRelocator } from '../file-relocator'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
+import { useCodeMirrorViewContext } from '../../codemirror-editor'
|
|
|
|
|
+import { EditorView } from '@codemirror/view'
|
|
|
|
|
+import { waitForFileTreeUpdate } from '../../../extensions/figure-modal'
|
|
|
|
|
|
|
|
function generateLinkedFileFetcher(
|
|
function generateLinkedFileFetcher(
|
|
|
projectId: string,
|
|
projectId: string,
|
|
|
url: string,
|
|
url: string,
|
|
|
name: string,
|
|
name: string,
|
|
|
- folder: File
|
|
|
|
|
|
|
+ folder: File,
|
|
|
|
|
+ view: EditorView
|
|
|
) {
|
|
) {
|
|
|
return async () => {
|
|
return async () => {
|
|
|
|
|
+ const fileTreeUpdate = waitForFileTreeUpdate(view)
|
|
|
await postJSON(`/project/${projectId}/linked_file`, {
|
|
await postJSON(`/project/${projectId}/linked_file`, {
|
|
|
body: {
|
|
body: {
|
|
|
parent_folder_id: folder.id,
|
|
parent_folder_id: folder.id,
|
|
@@ -24,6 +29,8 @@ function generateLinkedFileFetcher(
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
+ await fileTreeUpdate.withTimeout(500)
|
|
|
|
|
+
|
|
|
return folder.path === '' && folder.name === 'rootFolder'
|
|
return folder.path === '' && folder.name === 'rootFolder'
|
|
|
? `${name}`
|
|
? `${name}`
|
|
|
: `${folder.path ? folder.path + '/' : ''}${folder.name}/${name}`
|
|
: `${folder.path ? folder.path + '/' : ''}${folder.name}/${name}`
|
|
@@ -31,6 +38,7 @@ function generateLinkedFileFetcher(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const FigureModalUrlSource: FC = () => {
|
|
export const FigureModalUrlSource: FC = () => {
|
|
|
|
|
+ const view = useCodeMirrorViewContext()
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
const [url, setUrl] = useState<string>('')
|
|
const [url, setUrl] = useState<string>('')
|
|
|
const [nameDirty, setNameDirty] = useState<boolean>(false)
|
|
const [nameDirty, setNameDirty] = useState<boolean>(false)
|
|
@@ -53,7 +61,8 @@ export const FigureModalUrlSource: FC = () => {
|
|
|
projectId,
|
|
projectId,
|
|
|
newUrl,
|
|
newUrl,
|
|
|
newName,
|
|
newName,
|
|
|
- folder ?? rootFile
|
|
|
|
|
|
|
+ folder ?? rootFile,
|
|
|
|
|
+ view
|
|
|
),
|
|
),
|
|
|
})
|
|
})
|
|
|
} else if (getPath) {
|
|
} else if (getPath) {
|