Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NcAppContent): Allow to set the page title #5269

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.

Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de>
Co-authored-by: Grigorii K. Shartsev <me@shgk.me>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux and ShGKme committed May 10, 2024
commit 8dfc83f5c32eb4bfb95d9682a0d06bf1c27944e5
45 changes: 41 additions & 4 deletions src/components/NcAppContent/NcAppContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,22 @@ The list size must be between the min and the max width value.
</template>

<script>
import NcAppDetailsToggle from './NcAppDetailsToggle.vue'
import { useIsMobile } from '../../composables/useIsMobile/index.js'

import { getBuilder } from '@nextcloud/browser-storage'
import { emit } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'
import { useSwipe } from '@vueuse/core'
import { Splitpanes, Pane } from 'splitpanes'
import { useIsMobile } from '../../composables/useIsMobile/index.js'
import { t } from '../../l10n.js'

import NcAppDetailsToggle from './NcAppDetailsToggle.vue'

import 'splitpanes/dist/splitpanes.css'
import { emit } from '@nextcloud/event-bus'

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

/**
* App content container to be used for the main content of your app
Expand Down Expand Up @@ -223,6 +228,17 @@ export default {
return ['no-split', 'vertical-split', 'horizontal-split'].includes(value)
},
},

/**
* Allow setting the page's `<title>`
*
* If a page heading is set it defaults to `{pageHeading} - {appName} - {productName}` e.g. `Favorites - Files - Nextcloud`.
* When setting the prop then the following format will be used: `{pageTitle} - {pageHeading || appName} - {productName}`
susnux marked this conversation as resolved.
Show resolved Hide resolved
*/
pageTitle: {
type: String,
default: null,
},
},

emits: [
Expand Down Expand Up @@ -289,6 +305,27 @@ export default {
},
}
},

realPageTitle() {
if (this.pageTitle) {
return t('{view} - {app} - {product}', { view: this.pageTitle, app: this.pageHeading || localizedAppName, product: productName })
}
if (this.pageHeading) {
return t('{view} - {app} - {product}', { view: this.pageHeading, app: localizedAppName, product: productName })
}
susnux marked this conversation as resolved.
Show resolved Hide resolved
return null
},
},

watch: {
realPageTitle: {
immediate: true,
handler() {
if (this.realPageTitle !== null) {
document.title = this.realPageTitle
}
},
},
},

updated() {
Expand Down