Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Components/RightSidebar/AppFilesTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -55,6 +57,9 @@ export default {
if (this.unsubscribeUpdated) {
this.unsubscribeUpdated()
}
if (this.unsubscribeDeleted) {
this.unsubscribeDeleted()
}
},
methods: {
async checkAndLoadPendingEnvelope() {
Expand Down Expand Up @@ -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)
},
},
}
</script>
37 changes: 26 additions & 11 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/store/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading