Merge pull request #19089 from nextcloud/backport/18929/enh/sidebar/promise
[stable18] Allow to await the sidebar
This commit is contained in:
commit
9fd015353c
5 changed files with 53 additions and 57 deletions
BIN
apps/files/js/dist/sidebar.js
vendored
BIN
apps/files/js/dist/sidebar.js
vendored
Binary file not shown.
BIN
apps/files/js/dist/sidebar.js.map
vendored
BIN
apps/files/js/dist/sidebar.js.map
vendored
Binary file not shown.
|
@ -75,25 +75,6 @@ export default class Sidebar {
|
|||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the sidebar for the given file
|
||||
*
|
||||
* @memberof Sidebar
|
||||
* @param {string} path the file path to load
|
||||
*/
|
||||
open(path) {
|
||||
this.#state.file = path
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the sidebar
|
||||
*
|
||||
* @memberof Sidebar
|
||||
*/
|
||||
close() {
|
||||
this.#state.file = ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current opened file
|
||||
*
|
||||
|
|
|
@ -51,10 +51,11 @@ window.addEventListener('DOMContentLoaded', () => {
|
|||
}
|
||||
|
||||
// Init vue app
|
||||
const AppSidebar = new Vue({
|
||||
// eslint-disable-next-line vue/match-component-file-name
|
||||
const View = Vue.extend(SidebarView)
|
||||
const AppSidebar = new View({
|
||||
name: 'SidebarRoot',
|
||||
render: h => h(SidebarView),
|
||||
})
|
||||
AppSidebar.$mount('#app-sidebar')
|
||||
window.OCA.Files.Sidebar.open = AppSidebar.open
|
||||
window.OCA.Files.Sidebar.close = AppSidebar.close
|
||||
})
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
ref="sidebar"
|
||||
v-bind="appSidebar"
|
||||
:force-menu="true"
|
||||
@close="onClose"
|
||||
@close="close"
|
||||
@update:active="setActiveTab"
|
||||
@update:starred="toggleStarred"
|
||||
@[defaultActionListener].stop.prevent="onDefaultAction">
|
||||
|
@ -238,35 +238,6 @@ export default {
|
|||
|
||||
isSystemTagsEnabled() {
|
||||
return OCA && 'SystemTags' in OCA
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
// update the sidebar data
|
||||
async file(curr, prev) {
|
||||
this.resetData()
|
||||
if (curr && curr.trim() !== '') {
|
||||
try {
|
||||
this.fileInfo = await FileInfo(this.davPath)
|
||||
// adding this as fallback because other apps expect it
|
||||
this.fileInfo.dir = this.file.split('/').slice(0, -1).join('/')
|
||||
|
||||
// DEPRECATED legacy views
|
||||
// TODO: remove
|
||||
this.views.forEach(view => {
|
||||
view.setFileInfo(this.fileInfo)
|
||||
})
|
||||
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.sidebar) {
|
||||
this.$refs.sidebar.updateTabs()
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
this.error = t('files', 'Error while loading the file data')
|
||||
console.error('Error while loading the file data', error)
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -280,10 +251,6 @@ export default {
|
|||
canDisplay(tab) {
|
||||
return tab.isEnabled(this.fileInfo)
|
||||
},
|
||||
onClose() {
|
||||
this.resetData()
|
||||
OCA.Files.Sidebar.close()
|
||||
},
|
||||
resetData() {
|
||||
this.error = null
|
||||
this.fileInfo = null
|
||||
|
@ -406,7 +373,54 @@ export default {
|
|||
if (OCA.SystemTags && OCA.SystemTags.View) {
|
||||
OCA.SystemTags.View.toggle()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Open the sidebar for the given file
|
||||
*
|
||||
* @param {string} path the file path to load
|
||||
* @returns {Promise}
|
||||
* @throws {Error} loading failure
|
||||
*/
|
||||
async open(path) {
|
||||
// update current opened file
|
||||
this.Sidebar.file = path
|
||||
|
||||
// reset previous data
|
||||
this.resetData()
|
||||
if (path && path.trim() !== '') {
|
||||
try {
|
||||
this.fileInfo = await FileInfo(this.davPath)
|
||||
// adding this as fallback because other apps expect it
|
||||
this.fileInfo.dir = this.file.split('/').slice(0, -1).join('/')
|
||||
|
||||
// DEPRECATED legacy views
|
||||
// TODO: remove
|
||||
this.views.forEach(view => {
|
||||
view.setFileInfo(this.fileInfo)
|
||||
})
|
||||
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.sidebar) {
|
||||
this.$refs.sidebar.updateTabs()
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
this.error = t('files', 'Error while loading the file data')
|
||||
console.error('Error while loading the file data', error)
|
||||
|
||||
throw new Error(error)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Close the sidebar
|
||||
*/
|
||||
close() {
|
||||
this.Sidebar.file = ''
|
||||
this.resetData()
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue