Skip to content

Commit a277543

Browse files
refactor: improve sidebar title management in AppFilesTab
This refactoring enhances the sidebar behavior when working with envelopes and files: - Remove unused data properties (file, signers, requested_by, requestDate) - Add checkAndLoadPendingEnvelope() to handle envelope creation flow - Implement MutationObserver to maintain correct sidebar title - Add title synchronization for both envelopes and regular files - Prevent duplicate file loading when same file is already selected - Ensure proper cleanup of observers to prevent memory leaks The sidebar title now correctly displays the envelope or file name and resists being overwritten by Nextcloud's default behavior. Signed-off-by: Vitor Mattos <[email protected]>
1 parent 032ec5a commit a277543

1 file changed

Lines changed: 71 additions & 4 deletions

File tree

src/Components/RightSidebar/AppFilesTab.vue

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,73 @@ export default {
3030
},
3131
data() {
3232
return {
33-
file: {},
34-
signers: [],
35-
requested_by: {},
36-
requestDate: '',
33+
sidebarTitleObserver: null,
3734
}
3835
},
3936
methods: {
37+
checkAndLoadPendingEnvelope() {
38+
const pendingEnvelope = window.OCA?.Libresign?.pendingEnvelope
39+
if (pendingEnvelope?.id) {
40+
this.filesStore.addFile(pendingEnvelope)
41+
this.filesStore.selectFile(pendingEnvelope.id)
42+
delete window.OCA.Libresign.pendingEnvelope
43+
44+
this.$nextTick(() => {
45+
this.updateSidebarTitle(pendingEnvelope.name)
46+
})
47+
48+
return true
49+
}
50+
return false
51+
},
52+
53+
updateSidebarTitle(envelopeName) {
54+
if (!envelopeName) return
55+
56+
this.disconnectTitleObserver()
57+
58+
const titleElement = document.querySelector('.app-sidebar-header__mainname')
59+
60+
if (titleElement) {
61+
titleElement.textContent = envelopeName
62+
titleElement.setAttribute('title', envelopeName)
63+
64+
this.sidebarTitleObserver = new MutationObserver(() => {
65+
if (titleElement.textContent !== envelopeName) {
66+
titleElement.textContent = envelopeName
67+
titleElement.setAttribute('title', envelopeName)
68+
}
69+
})
70+
71+
this.sidebarTitleObserver.observe(titleElement, {
72+
childList: true,
73+
characterData: true,
74+
subtree: true
75+
})
76+
77+
setTimeout(() => this.disconnectTitleObserver(), 5000)
78+
}
79+
},
80+
81+
disconnectTitleObserver() {
82+
if (this.sidebarTitleObserver) {
83+
console.log('Disconnecting sidebar title observer')
84+
this.sidebarTitleObserver.disconnect()
85+
this.sidebarTitleObserver = null
86+
}
87+
},
88+
4089
async update(fileInfo) {
90+
if (this.checkAndLoadPendingEnvelope()) {
91+
return
92+
}
93+
94+
this.disconnectTitleObserver()
95+
96+
if (this.filesStore.selectedId === fileInfo.id) {
97+
return
98+
}
99+
41100
this.filesStore.addFile({
42101
nodeId: fileInfo.id,
43102
name: fileInfo.name,
@@ -46,6 +105,14 @@ export default {
46105
signers: [],
47106
})
48107
this.filesStore.selectFile(fileInfo.id)
108+
109+
this.$nextTick(() => {
110+
const titleElement = document.querySelector('.app-sidebar-header__mainname')
111+
if (titleElement) {
112+
titleElement.textContent = fileInfo.name
113+
titleElement.setAttribute('title', fileInfo.name)
114+
}
115+
})
49116
},
50117
},
51118
}

0 commit comments

Comments
 (0)