diff --git a/src/Components/RightSidebar/AppFilesTab.vue b/src/Components/RightSidebar/AppFilesTab.vue index 358e0a6cf8..1eb2e39757 100644 --- a/src/Components/RightSidebar/AppFilesTab.vue +++ b/src/Components/RightSidebar/AppFilesTab.vue @@ -41,11 +41,13 @@ export default { sidebarTitleObserver: null, unsubscribeCreated: null, unsubscribeUpdated: null, + unsubscribeDeleted: null, } }, mounted() { this.unsubscribeCreated = subscribe('libresign:file:created', this.handleLibreSignFileCreated) this.unsubscribeUpdated = subscribe('libresign:file:updated', this.handleLibreSignFileUpdated) + this.unsubscribeDeleted = subscribe('files:node:deleted', this.handleFilesNodeDeleted) }, beforeUnmount() { this.disconnectTitleObserver() @@ -55,6 +57,9 @@ export default { if (this.unsubscribeUpdated) { this.unsubscribeUpdated() } + if (this.unsubscribeDeleted) { + this.unsubscribeDeleted() + } }, methods: { async checkAndLoadPendingEnvelope() { @@ -194,6 +199,17 @@ export default { async handleLibreSignFileUpdated(payload) { await this.handleLibreSignFileChange(payload, 'updated') }, + + handleFilesNodeDeleted(node) { + const rawNodeId = node?.fileid ?? node?.id ?? node?.fileId ?? node?.nodeId + const nodeId = typeof rawNodeId === 'string' ? parseInt(rawNodeId, 10) : rawNodeId + + if (!nodeId) { + return + } + + this.filesStore.removeFileByNodeId(nodeId) + }, }, } diff --git a/src/store/files.js b/src/store/files.js index 311ea66d43..9a0e83222f 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -36,6 +36,31 @@ export const useFilesStore = function(...args) { }, actions: { + removeFileById(fileId) { + if (!fileId) { + return + } + + if (this.selectedFileId === fileId) { + const sidebarStore = useSidebarStore() + sidebarStore.hideSidebar() + this.selectedFileId = 0 + } + + del(this.files, fileId) + const index = this.ordered.indexOf(fileId) + if (index > -1) { + this.ordered.splice(index, 1) + } + }, + removeFileByNodeId(nodeId) { + const fileId = this.getFileIdByNodeId(nodeId) + if (!fileId) { + return + } + + this.removeFileById(fileId) + }, async addFile(file) { if (!file.id && !file.nodeId) { console.warn('[LibreSign] File must have id or nodeId:', file) @@ -367,17 +392,7 @@ export const useFilesStore = function(...args) { fileId: fileId, }), { params }) .then(async () => { - if (this.selectedFileId === fileId) { - const sidebarStore = useSidebarStore() - sidebarStore.hideSidebar() - this.selectedFileId = 0 - } - - del(this.files, fileId) - const index = this.ordered.indexOf(fileId) - if (index > -1) { - this.ordered.splice(index, 1) - } + this.removeFileById(fileId) }) } diff --git a/src/store/sign.js b/src/store/sign.js index 33f6877cb6..f500b946bc 100644 --- a/src/store/sign.js +++ b/src/store/sign.js @@ -48,10 +48,11 @@ export const useSignStore = defineStore('sign', { signers: loadState('libresign', 'signers', []), } const filesStore = useFilesStore() + const sidebarStore = useSidebarStore() await filesStore.addFile(file) filesStore.selectFile(file.id) this.setFileToSign(file) - this.sidebarStore.activeSignTab() + sidebarStore.activeSignTab() }, setFileToSign(file) { if (file) {