diff --git a/frontend/src/components/RepositorySwitch.vue b/frontend/src/components/RepositorySwitch.vue index d3fa59bd..f8bde7a2 100644 --- a/frontend/src/components/RepositorySwitch.vue +++ b/frontend/src/components/RepositorySwitch.vue @@ -23,10 +23,9 @@ export default { } }, created () { + this.current = this.getRepo() this.fetchRepositories() }, - mounted () { - }, beforeDestroy () { }, methods: { @@ -34,19 +33,27 @@ export default { file.fetchRepositories(data => { this.list = data const keys = Object.keys(data) - if (keys.length > 0) { + + if (keys.length > 0 && !keys.includes(this.current)) { this.choose(keys[0]) } }) }, choose (name) { this.current = name + }, + storeRepo (name) { + window.localStorage['repository'] = name + }, + getRepo () { + return window.localStorage['repository'] || null } }, watch: { current (val) { if (val) { this.$bus.emit('switch-repository', val) + this.storeRepo(this.current) } } }, diff --git a/frontend/src/components/Tree.vue b/frontend/src/components/Tree.vue index 72f173af..261e862b 100644 --- a/frontend/src/components/Tree.vue +++ b/frontend/src/components/Tree.vue @@ -51,6 +51,7 @@ export default { if (repo) { this.repo = repo this.tree = null + this.file = null } File.tree(this.repo, tree => { diff --git a/frontend/src/components/TreeNode.vue b/frontend/src/components/TreeNode.vue index 81c190b9..4e864eb7 100644 --- a/frontend/src/components/TreeNode.vue +++ b/frontend/src/components/TreeNode.vue @@ -42,14 +42,20 @@ export default { } }, mounted () { - this.$bus.on('editor-ready', () => { - this.chooseFile(this.getSelectedFilePath()) - }) - this.$bus.on('choose-file', file => { - this.chooseFile(file.path) - }) + this.$bus.on('editor-ready', this.handleEditorReady) + this.$bus.on('choose-file', this.handleChooseFile) + }, + beforeDestroy () { + this.$bus.off('editor-ready', this.handleEditorReady) + this.$bus.off('choose-file', this.handleChooseFile) }, methods: { + handleEditorReady () { + this.chooseFile(this.getSelectedFilePath()) + }, + handleChooseFile (file) { + this.chooseFile(file.path) + }, chooseFile (filePath) { if (this.item.type === 'dir' && filePath.startsWith(this.item.path)) { this.$refs.dir.open = true