Skip to content

Commit 1db6ecf

Browse files
authored
Merge pull request #6371 from LibreSign/backport/6369/stable32
[stable32] fix: align frontend file ids
2 parents d52d598 + f6e9460 commit 1db6ecf

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

src/Components/RightSidebar/AppFilesTab.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ export default {
4141
sidebarTitleObserver: null,
4242
unsubscribeCreated: null,
4343
unsubscribeUpdated: null,
44+
unsubscribeDeleted: null,
4445
}
4546
},
4647
mounted() {
4748
this.unsubscribeCreated = subscribe('libresign:file:created', this.handleLibreSignFileCreated)
4849
this.unsubscribeUpdated = subscribe('libresign:file:updated', this.handleLibreSignFileUpdated)
50+
this.unsubscribeDeleted = subscribe('files:node:deleted', this.handleFilesNodeDeleted)
4951
},
5052
beforeUnmount() {
5153
this.disconnectTitleObserver()
@@ -55,6 +57,9 @@ export default {
5557
if (this.unsubscribeUpdated) {
5658
this.unsubscribeUpdated()
5759
}
60+
if (this.unsubscribeDeleted) {
61+
this.unsubscribeDeleted()
62+
}
5863
},
5964
methods: {
6065
async checkAndLoadPendingEnvelope() {
@@ -194,6 +199,17 @@ export default {
194199
async handleLibreSignFileUpdated(payload) {
195200
await this.handleLibreSignFileChange(payload, 'updated')
196201
},
202+
203+
handleFilesNodeDeleted(node) {
204+
const rawNodeId = node?.fileid ?? node?.id ?? node?.fileId ?? node?.nodeId
205+
const nodeId = typeof rawNodeId === 'string' ? parseInt(rawNodeId, 10) : rawNodeId
206+
207+
if (!nodeId) {
208+
return
209+
}
210+
211+
this.filesStore.removeFileByNodeId(nodeId)
212+
},
197213
},
198214
}
199215
</script>

src/store/files.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ export const useFilesStore = function(...args) {
3636
},
3737

3838
actions: {
39+
removeFileById(fileId) {
40+
if (!fileId) {
41+
return
42+
}
43+
44+
if (this.selectedFileId === fileId) {
45+
const sidebarStore = useSidebarStore()
46+
sidebarStore.hideSidebar()
47+
this.selectedFileId = 0
48+
}
49+
50+
del(this.files, fileId)
51+
const index = this.ordered.indexOf(fileId)
52+
if (index > -1) {
53+
this.ordered.splice(index, 1)
54+
}
55+
},
56+
removeFileByNodeId(nodeId) {
57+
const fileId = this.getFileIdByNodeId(nodeId)
58+
if (!fileId) {
59+
return
60+
}
61+
62+
this.removeFileById(fileId)
63+
},
3964
async addFile(file) {
4065
if (!file.id && !file.nodeId) {
4166
console.warn('[LibreSign] File must have id or nodeId:', file)
@@ -374,17 +399,7 @@ export const useFilesStore = function(...args) {
374399
fileId: fileId,
375400
}), { params })
376401
.then(async () => {
377-
if (this.selectedFileId === fileId) {
378-
const sidebarStore = useSidebarStore()
379-
sidebarStore.hideSidebar()
380-
this.selectedFileId = 0
381-
}
382-
383-
del(this.files, fileId)
384-
const index = this.ordered.indexOf(fileId)
385-
if (index > -1) {
386-
this.ordered.splice(index, 1)
387-
}
402+
this.removeFileById(fileId)
388403
})
389404
}
390405

src/store/sign.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ export const useSignStore = defineStore('sign', {
4848
signers: loadState('libresign', 'signers', []),
4949
}
5050
const filesStore = useFilesStore()
51+
const sidebarStore = useSidebarStore()
5152
await filesStore.addFile(file)
5253
filesStore.selectFile(file.id)
5354
this.setFileToSign(file)
54-
this.sidebarStore.activeSignTab()
55+
sidebarStore.activeSignTab()
5556
},
5657
setFileToSign(file) {
5758
if (file) {

0 commit comments

Comments
 (0)