From 0e207b84302fb67146481e0c796864ef4b1c2af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 13 Nov 2023 02:24:55 +0100 Subject: [PATCH] fix: Update browser page title depending on current view/table (#668) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/App.vue | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/App.vue b/src/App.vue index 87ad00a71..40b2fe25e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -33,6 +33,7 @@ export default { data() { return { loading: false, + defaultPageTitle: false, } }, computed: { @@ -60,10 +61,29 @@ export default { } if (currentRoute.path.startsWith('/table/')) { this.$store.commit('setActiveTableId', parseInt(currentRoute.params.tableId)) + this.setPageTitle(this.$store.getters.activeTable.title) } else if (currentRoute.path.startsWith('/view/')) { this.$store.commit('setActiveViewId', parseInt(currentRoute.params.viewId)) + this.setPageTitle(this.$store.getters.activeView.title) } }, + setPageTitle(title) { + if (this.defaultPageTitle === false) { + const appTitle = t('tables', 'Tables') + this.defaultPageTitle = window.document.title + if (this.defaultPageTitle.indexOf(` - ${appTitle} - `) !== -1) { + this.defaultPageTitle = this.defaultPageTitle.substring(this.defaultPageTitle.indexOf(` - ${appTitle} - `) + 3) + } + if (this.defaultPageTitle.indexOf(`${appTitle} - `) !== 0) { + this.defaultPageTitle = `${appTitle} - ` + this.defaultPageTitle + } + } + let newTitle = this.defaultPageTitle + if (title !== '') { + newTitle = `${title} - ${newTitle}` + } + window.document.title = newTitle + }, }, }