Allow to await the sidebar

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2020-01-16 15:28:03 +01:00
parent cbe2bafc7a
commit 6201b0b5b1
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
3 changed files with 42 additions and 43 deletions

View File

@ -75,16 +75,6 @@ export default class Sidebar {
return false 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 * Close the sidebar
* *

View File

@ -51,10 +51,10 @@ window.addEventListener('DOMContentLoaded', () => {
} }
// Init vue app // Init vue app
const AppSidebar = new Vue({ const View = Vue.extend(SidebarView)
// eslint-disable-next-line vue/match-component-file-name const AppSidebar = new View({
name: 'SidebarRoot', name: 'SidebarRoot',
render: h => h(SidebarView),
}) })
AppSidebar.$mount('#app-sidebar') AppSidebar.$mount('#app-sidebar')
window.OCA.Files.Sidebar.open = AppSidebar.open
}) })

View File

@ -237,35 +237,6 @@ export default {
isSystemTagsEnabled() { isSystemTagsEnabled() {
return OCA && 'SystemTags' in OCA 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)
}
}
}, },
}, },
@ -405,7 +376,45 @@ export default {
if (OCA.SystemTags && OCA.SystemTags.View) { if (OCA.SystemTags && OCA.SystemTags.View) {
OCA.SystemTags.View.toggle() OCA.SystemTags.View.toggle()
} }
} },
/**
* Open the sidebar for the given file
*
* @memberof Sidebar
* @param {string} path the file path to load
*/
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)
}
}
},
}, },
} }
</script> </script>