Skip to content

Commit 1e94b84

Browse files
committed
refresh files page after exporting a file
Signed-off-by: silver <[email protected]>
1 parent 5b25e71 commit 1e94b84

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/export-refresh-listener.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { subscribe, emit } from '@nextcloud/event-bus'
7+
8+
/**
9+
* Reloads the current directory in the Files app
10+
*/
11+
function triggerUIRefresh() {
12+
// Only run in Files app
13+
if (!window.location.pathname.includes('/apps/files')) {
14+
return
15+
}
16+
17+
emit('files:list:changed')
18+
19+
const urlParams = new URLSearchParams(window.location.search)
20+
const currentDir = urlParams.get('dir') || '/'
21+
const cleanUrl = `${window.location.origin}/index.php/apps/files/files?dir=${encodeURIComponent(currentDir)}`
22+
window.location.href = cleanUrl
23+
}
24+
25+
// Listen for export completion events and and trigger a delayed refresh
26+
subscribe('richdocuments:export-completed', (event) => {
27+
// Minimal delay to ensure we're back in Files app context
28+
setTimeout(() => {
29+
triggerUIRefresh()
30+
}, 200)
31+
})
32+
33+
// Also provide immediate refresh functionality for other triggers
34+
window.richdocumentsRefreshFiles = triggerUIRefresh

src/file-actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { registerFileAction, FileAction } from '@nextcloud/files'
66
import { getCapabilities } from './services/capabilities.ts'
77
import { translate as t } from '@nextcloud/l10n'
88

9+
// Import the export refresh listener to initialize it
10+
import './export-refresh-listener.js'
11+
912
// eslint-disable-next-line import/no-unresolved
1013
import appIcon from '../img/app.svg?raw'
1114

src/view/Office.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
8787
import AlertOctagonOutline from 'vue-material-design-icons/AlertOctagonOutline.vue'
8888
import { loadState } from '@nextcloud/initial-state'
8989
import { showInfo, spawnDialog } from '@nextcloud/dialogs'
90+
import { emit } from '@nextcloud/event-bus'
9091
9192
import ZoteroHint from '../components/Modal/ZoteroHint.vue'
9293
import { basename, dirname } from 'path'
@@ -191,6 +192,7 @@ export default {
191192
showZotero: false,
192193
modified: false,
193194
hasWidgetEditingEnabled: false,
195+
recentExport: false,
194196
195197
formData: {
196198
action: null,
@@ -415,12 +417,19 @@ export default {
415417
}
416418
break
417419
case 'UI_Close':
420+
// If we recently did a saveAs operation, emit refresh event
421+
if (this.recentExport) {
422+
emit('richdocuments:export-completed', {
423+
timestamp: Date.now(),
424+
})
425+
}
418426
this.close()
419427
break
420428
case 'Session_Closed':
421429
this.handleSessionClosed(args)
422430
break
423431
case 'UI_SaveAs':
432+
this.recentExport = true
424433
this.saveAs(args.format)
425434
break
426435
case 'Action_Save_Resp':

0 commit comments

Comments
 (0)