AppDesktop.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import useFormKitConfig from '#shared/composables/form/useFormKitConfig.ts'
  4. import CommonButton from '#desktop/components/CommonButton/CommonButton.vue'
  5. import CommonNotifications from '#shared/components/CommonNotifications/CommonNotifications.vue'
  6. import useAppMaintenanceCheck from '#shared/composables/useAppMaintenanceCheck.ts'
  7. import { useAppTheme } from '#shared/stores/theme.ts'
  8. import useAuthenticationChanges from '#shared/composables/authentication/useAuthenticationUpdates.ts'
  9. import useMetaTitle from '#shared/composables/useMetaTitle.ts'
  10. import usePushMessages from '#shared/composables/usePushMessages.ts'
  11. import { useApplicationStore } from '#shared/stores/application.ts'
  12. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  13. import { useLocaleStore } from '#shared/stores/locale.ts'
  14. import emitter from '#shared/utils/emitter.ts'
  15. import { onBeforeMount, onBeforeUnmount } from 'vue'
  16. import { useRouter } from 'vue-router'
  17. import LayoutSidebar from './components/layout/LayoutSidebar.vue'
  18. const router = useRouter()
  19. const authentication = useAuthenticationStore()
  20. useMetaTitle().initializeMetaTitle()
  21. const application = useApplicationStore()
  22. onBeforeMount(() => {
  23. application.setLoaded()
  24. })
  25. useAppMaintenanceCheck()
  26. usePushMessages()
  27. // Add a check for authenticated changes (e.g. login/logout in a other
  28. // browser tab or maintenance mode switch).
  29. useAuthenticationChanges()
  30. // We need to trigger a manual translation update for the form related strings.
  31. const formConfig = useFormKitConfig()
  32. useLocaleStore().$subscribe(() => {
  33. formConfig.locale = 'staticLocale'
  34. })
  35. // The handling for invalid sessions. The event will be emitted, when from the server a "NotAuthorized"
  36. // response is received.
  37. emitter.on('sessionInvalid', async () => {
  38. if (authentication.authenticated) {
  39. await authentication.clearAuthentication()
  40. router.replace({
  41. name: 'Login',
  42. query: {
  43. invalidatedSession: '1',
  44. },
  45. })
  46. }
  47. })
  48. // Initialize the ticket overview store after a valid session is present on
  49. // the app level, so that the query keeps alive.
  50. // watch(
  51. // () => session.initialized,
  52. // (newValue, oldValue) => {
  53. // if (!oldValue && newValue) {
  54. // useTicketOverviewsStore()
  55. // }
  56. // },
  57. // { immediate: true },
  58. // )
  59. onBeforeUnmount(() => {
  60. emitter.off('sessionInvalid')
  61. })
  62. const appTheme = useAppTheme()
  63. </script>
  64. <template>
  65. <template v-if="application.loaded">
  66. <CommonNotifications />
  67. <CommonButton
  68. class="fixed top-2 ltr:right-2 rtl:left-2"
  69. size="medium"
  70. aria-label="Change theme"
  71. :icon="appTheme.theme === 'light' ? 'sun' : 'moon'"
  72. @click="appTheme.toggleTheme(false)"
  73. />
  74. </template>
  75. <!-- TODO: styles are placeholders -->
  76. <div v-if="application.loaded" class="flex h-full">
  77. <aside
  78. v-if="$route.meta.sidebar !== false"
  79. class="w-1/5"
  80. :aria-label="__('Sidebar')"
  81. >
  82. <LayoutSidebar />
  83. </aside>
  84. <article
  85. class="w-full h-full antialiased bg-white dark:bg-gray-500 text-gray-100 dark:text-neutral-400 overflow-hidden"
  86. >
  87. <RouterView />
  88. </article>
  89. </div>
  90. </template>