Skip to content

Commit 1181ddb

Browse files
committed
feat(NcAppContent): Allow to set the page title
Sometimes - e.g. when you have multiple view - you want to adjust the page title, that is shown as the browsers tab name. This adds a property to set that value. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 7805800 commit 1181ddb

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"@nextcloud/calendar-js": "^6.0.0",
7373
"@nextcloud/capabilities": "^1.0.4",
7474
"@nextcloud/event-bus": "^3.0.0",
75-
"@nextcloud/initial-state": "^2.0.0",
75+
"@nextcloud/initial-state": "^2.1.0",
7676
"@nextcloud/l10n": "^2.0.1",
7777
"@nextcloud/logger": "^2.2.1",
7878
"@nextcloud/router": "^3.0.0",

src/components/NcAppContent/NcAppContent.vue

+37-3
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,22 @@ The list size must be between the min and the max width value.
115115
</template>
116116

117117
<script>
118-
import NcAppDetailsToggle from './NcAppDetailsToggle.vue'
119-
import { useIsMobile } from '../../composables/useIsMobile/index.js'
120-
121118
import { getBuilder } from '@nextcloud/browser-storage'
122119
import { emit } from '@nextcloud/event-bus'
120+
import { loadState } from '@nextcloud/initial-state'
123121
import { useSwipe } from '@vueuse/core'
124122
import { Splitpanes, Pane } from 'splitpanes'
123+
import { useIsMobile } from '../../composables/useIsMobile/index.js'
124+
import { t } from '../../l10n.js'
125+
126+
import NcAppDetailsToggle from './NcAppDetailsToggle.vue'
125127

126128
import 'splitpanes/dist/splitpanes.css'
127129

128130
const browserStorage = getBuilder('nextcloud').persist().build()
131+
const { name: productName } = loadState('theming', 'data', { name: 'Nextcloud' })
132+
const activeApp = loadState('core', 'active-app', appName)
133+
const localizedAppName = loadState('core', 'apps', {})[activeApp]?.name ?? appName
129134

130135
/**
131136
* App content container to be used for the main content of your app
@@ -202,6 +207,17 @@ export default {
202207
type: String,
203208
default: null,
204209
},
210+
211+
/**
212+
* Allow setting the page's `<title>`
213+
*
214+
* If a page heading is set it defaults to `{pageHeading} - {appName} - {productName}` e.g. `Favorites - Files - Nextcloud`.
215+
* If both `pageTitle` and `pageHeading` are unset the initial `<title>` will not be changed.
216+
*/
217+
pageTitle: {
218+
type: String,
219+
default: null,
220+
},
205221
},
206222

207223
emits: [
@@ -268,6 +284,24 @@ export default {
268284
},
269285
}
270286
},
287+
288+
realPageTitle() {
289+
if (this.pageTitle) {
290+
return this.pageTitle
291+
}
292+
if (this.pageHeading) {
293+
return t('{view} - {app} - {product}', { view: this.pageHeading, app: localizedAppName, product: productName })
294+
}
295+
return null
296+
},
297+
},
298+
299+
watch: {
300+
realPageTitle() {
301+
if (this.realPageTitle !== null) {
302+
window.document.title = this.realPageTitle
303+
}
304+
},
271305
},
272306

273307
updated() {

0 commit comments

Comments
 (0)