@@ -45,10 +45,10 @@ import type { IFolder, INode, IView } from '@nextcloud/files'
4545import type { Version } from ' ../utils/versions.ts'
4646
4747import { showError , showSuccess } from ' @nextcloud/dialogs'
48- import { emit } from ' @nextcloud/event-bus'
48+ import { emit , subscribe , unsubscribe } from ' @nextcloud/event-bus'
4949import { t } from ' @nextcloud/l10n'
5050import { useIsMobile } from ' @nextcloud/vue/composables/useIsMobile'
51- import { computed , ref , toRef , watch } from ' vue'
51+ import { computed , onBeforeUnmount , onMounted , ref , toRef , watch } from ' vue'
5252import NcLoadingIcon from ' @nextcloud/vue/components/NcLoadingIcon'
5353import VersionEntry from ' ../components/VersionEntry.vue'
5454import VersionLabelDialog from ' ../components/VersionLabelDialog.vue'
@@ -72,19 +72,52 @@ const loading = ref(false)
7272const showVersionLabelForm = ref (false )
7373const editedVersion = ref <Version | null >(null )
7474
75- watch (toRef (() => props .node ), async () => {
75+ /**
76+ * Reload versions for the current file
77+ */
78+ async function reloadVersions() {
7679 if (! props .node ) {
7780 return
7881 }
7982
83+ const previousCount = versions .value .length
84+
8085 try {
8186 loading .value = true
8287 versions .value = await fetchVersions (props .node )
88+ console .debug (' [FilesVersionsSidebarTab] Reloaded versions:' , previousCount , ' →' , versions .value .length )
8389 } finally {
8490 loading .value = false
8591 }
92+ }
93+
94+ /**
95+ * Handle files:node:updated event to reload versions when the current file is saved
96+ * @param node
97+ */
98+ function handleNodeUpdated(node : INode ) {
99+ // Only reload if this is the currently open file and the tab is active
100+ if (props .active && props .node && node .source === props .node .source ) {
101+ console .debug (' [FilesVersionsSidebarTab] File saved, reloading versions in 1s' )
102+ // Delay to let the server create the new version
103+ setTimeout (() => {
104+ reloadVersions ()
105+ }, 1000 )
106+ }
107+ }
108+
109+ watch (toRef (() => props .node ), async () => {
110+ await reloadVersions ()
86111}, { immediate: true })
87112
113+ onMounted (() => {
114+ subscribe (' files:node:updated' , handleNodeUpdated )
115+ })
116+
117+ onBeforeUnmount (() => {
118+ unsubscribe (' files:node:updated' , handleNodeUpdated )
119+ })
120+
88121const currentVersionMtime = computed (() => props .node ?.mtime ?.getTime () ?? 0 )
89122
90123/**
0 commit comments