Skip to content

Commit 9fd0153

Browse files
authored
Merge pull request #19089 from nextcloud/backport/18929/enh/sidebar/promise
[stable18] Allow to await the sidebar
2 parents 6e876fa + b074be1 commit 9fd0153

5 files changed

Lines changed: 59 additions & 63 deletions

File tree

apps/files/js/dist/sidebar.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files/js/dist/sidebar.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files/src/services/Sidebar.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,6 @@ export default class Sidebar {
7575
return false
7676
}
7777

78-
/**
79-
* Open the sidebar for the given file
80-
*
81-
* @memberof Sidebar
82-
* @param {string} path the file path to load
83-
*/
84-
open(path) {
85-
this.#state.file = path
86-
}
87-
88-
/**
89-
* Close the sidebar
90-
*
91-
* @memberof Sidebar
92-
*/
93-
close() {
94-
this.#state.file = ''
95-
}
96-
9778
/**
9879
* Return current opened file
9980
*

apps/files/src/sidebar.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ window.addEventListener('DOMContentLoaded', () => {
5151
}
5252

5353
// Init vue app
54-
const AppSidebar = new Vue({
55-
// eslint-disable-next-line vue/match-component-file-name
54+
const View = Vue.extend(SidebarView)
55+
const AppSidebar = new View({
5656
name: 'SidebarRoot',
57-
render: h => h(SidebarView),
5857
})
5958
AppSidebar.$mount('#app-sidebar')
59+
window.OCA.Files.Sidebar.open = AppSidebar.open
60+
window.OCA.Files.Sidebar.close = AppSidebar.close
6061
})

apps/files/src/views/Sidebar.vue

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
ref="sidebar"
2727
v-bind="appSidebar"
2828
:force-menu="true"
29-
@close="onClose"
29+
@close="close"
3030
@update:active="setActiveTab"
3131
@update:starred="toggleStarred"
3232
@[defaultActionListener].stop.prevent="onDefaultAction">
@@ -238,35 +238,6 @@ export default {
238238
239239
isSystemTagsEnabled() {
240240
return OCA && 'SystemTags' in OCA
241-
}
242-
},
243-
244-
watch: {
245-
// update the sidebar data
246-
async file(curr, prev) {
247-
this.resetData()
248-
if (curr && curr.trim() !== '') {
249-
try {
250-
this.fileInfo = await FileInfo(this.davPath)
251-
// adding this as fallback because other apps expect it
252-
this.fileInfo.dir = this.file.split('/').slice(0, -1).join('/')
253-
254-
// DEPRECATED legacy views
255-
// TODO: remove
256-
this.views.forEach(view => {
257-
view.setFileInfo(this.fileInfo)
258-
})
259-
260-
this.$nextTick(() => {
261-
if (this.$refs.sidebar) {
262-
this.$refs.sidebar.updateTabs()
263-
}
264-
})
265-
} catch (error) {
266-
this.error = t('files', 'Error while loading the file data')
267-
console.error('Error while loading the file data', error)
268-
}
269-
}
270241
},
271242
},
272243
@@ -280,10 +251,6 @@ export default {
280251
canDisplay(tab) {
281252
return tab.isEnabled(this.fileInfo)
282253
},
283-
onClose() {
284-
this.resetData()
285-
OCA.Files.Sidebar.close()
286-
},
287254
resetData() {
288255
this.error = null
289256
this.fileInfo = null
@@ -406,7 +373,54 @@ export default {
406373
if (OCA.SystemTags && OCA.SystemTags.View) {
407374
OCA.SystemTags.View.toggle()
408375
}
409-
}
376+
},
377+
378+
/**
379+
* Open the sidebar for the given file
380+
*
381+
* @param {string} path the file path to load
382+
* @returns {Promise}
383+
* @throws {Error} loading failure
384+
*/
385+
async open(path) {
386+
// update current opened file
387+
this.Sidebar.file = path
388+
389+
// reset previous data
390+
this.resetData()
391+
if (path && path.trim() !== '') {
392+
try {
393+
this.fileInfo = await FileInfo(this.davPath)
394+
// adding this as fallback because other apps expect it
395+
this.fileInfo.dir = this.file.split('/').slice(0, -1).join('/')
396+
397+
// DEPRECATED legacy views
398+
// TODO: remove
399+
this.views.forEach(view => {
400+
view.setFileInfo(this.fileInfo)
401+
})
402+
403+
this.$nextTick(() => {
404+
if (this.$refs.sidebar) {
405+
this.$refs.sidebar.updateTabs()
406+
}
407+
})
408+
} catch (error) {
409+
this.error = t('files', 'Error while loading the file data')
410+
console.error('Error while loading the file data', error)
411+
412+
throw new Error(error)
413+
}
414+
}
415+
},
416+
417+
/**
418+
* Close the sidebar
419+
*/
420+
close() {
421+
this.Sidebar.file = ''
422+
this.resetData()
423+
},
410424
},
411425
}
412426
</script>

0 commit comments

Comments
 (0)