Skip to content

Commit 64cf8ef

Browse files
committed
feat: show newly exported or saved files in list without page reload
Signed-off-by: silver <[email protected]>
1 parent 5b55e0d commit 64cf8ef

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

src/mixins/saveAs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { spawnDialog } from '@nextcloud/dialogs'
7+
import { basename } from 'path'
78
import SaveAs from '../components/Modal/SaveAs.vue'
89

910
export default {
@@ -16,7 +17,13 @@ export default {
1617
format,
1718
description: t('richdocuments', 'Save a copy of the file under a new name and continue editing the new file'),
1819
},
19-
(value) => value && this.sendPostMessage('Action_SaveAs', { Filename: value, Notify: true }),
20+
(value) => {
21+
if (value) {
22+
// Track the requested filename for export operations
23+
this.lastSaveAsFilename = basename(value)
24+
this.sendPostMessage('Action_SaveAs', { Filename: value, Notify: true })
25+
}
26+
},
2027
)
2128
},
2229
},

src/view/FilesAppIntegration.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,42 @@ export default {
537537
return this.fileNode
538538
},
539539

540+
/**
541+
* Fetch metadata for a newly created file and emit files:node:created event
542+
* This is used when exporting a document (e.g., DOCX -> PDF) to make the
543+
* new file appear in the files list without manual reload
544+
*
545+
* @param {string} basename - The name of the new file (e.g., "test.pdf")
546+
*/
547+
async createNodeForNewFile(basename) {
548+
if (isPublicShare()) {
549+
return
550+
}
551+
552+
try {
553+
// Query the directory containing the file, not the file itself
554+
const client = davGetClient()
555+
const results = await client.getDirectoryContents(`${davRootPath}${this.filePath}`, {
556+
details: true,
557+
data: davGetDefaultPropfind(),
558+
})
559+
560+
// Find the specific file in the directory listing
561+
const nodes = results.data
562+
.map((result) => davResultToNode(result))
563+
.filter((node) => node.basename === basename)
564+
565+
if (nodes[0]) {
566+
console.debug('[FilesAppIntegration] Emitting files:node:created for', basename)
567+
emit('files:node:created', nodes[0])
568+
} else {
569+
console.warn('[FilesAppIntegration] New file not found in directory:', basename)
570+
}
571+
} catch (e) {
572+
console.error('Failed to fetch new file metadata from webdav', e)
573+
}
574+
},
575+
540576
changeFilesRoute(fileId) {
541577
OCP?.Files?.Router?.goToRoute(
542578
OCP.Files.Router.name,

src/view/Office.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ export default {
192192
modified: false,
193193
hasWidgetEditingEnabled: false,
194194
195+
// Track the last requested save-as filename for export operations
196+
lastSaveAsFilename: null,
197+
195198
formData: {
196199
action: null,
197200
accessToken: null,
@@ -425,8 +428,24 @@ export default {
425428
this.saveAs(args.format)
426429
break
427430
case 'Action_Save_Resp':
428-
if (args.fileName !== this.filename) {
429-
FilesAppIntegration.saveAs(args.fileName)
431+
console.debug('[viewer] Received post message Action_Save_Resp', args, this.lastSaveAsFilename)
432+
if (args.success) {
433+
let newFileName = args.fileName
434+
435+
// If no filename is provided for exportas, use the last tracked filename
436+
if (!newFileName && args.result === 'exportas' && this.lastSaveAsFilename) {
437+
newFileName = this.lastSaveAsFilename
438+
}
439+
440+
if (newFileName && newFileName !== this.filename) {
441+
// When exporting (e.g., DOCX -> PDF), a new file is created
442+
// Fetch its metadata and emit files:node:created to show it in the files list
443+
FilesAppIntegration.createNodeForNewFile(newFileName)
444+
} else {
445+
// When saving the current file, update its modification time
446+
FilesAppIntegration.updateFileInfo(undefined, Date.now())
447+
}
448+
this.lastSaveAsFilename = null
430449
}
431450
break
432451
case 'UI_InsertGraphic':

0 commit comments

Comments
 (0)