123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- import {
- computed,
- onActivated,
- onDeactivated,
- ref,
- watch,
- type ComputedRef,
- type WatchHandle,
- } from 'vue'
- import useMetaTitle from '#shared/composables/useMetaTitle.ts'
- interface PageOptions {
- metaTitle?: ComputedRef<string>
- }
- export const usePage = (pageOptions: PageOptions) => {
- const pageActive = ref(true)
- const pageInactive = computed(() => !pageActive.value)
- const { metaTitle } = pageOptions
- let stopMetaTitleWatcher: WatchHandle | undefined
- const { setViewTitle } = useMetaTitle()
- onActivated(() => {
- pageActive.value = true
- if (metaTitle) {
- stopMetaTitleWatcher = watch(
- metaTitle,
- (newValue) => {
- setViewTitle(newValue)
- },
- { immediate: true },
- )
- }
- })
- onDeactivated(() => {
- pageActive.value = false
- stopMetaTitleWatcher?.()
- })
- return {
- pageActive,
- pageInactive,
- }
- }
|