UserTaskbarTabRemove.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { useRouter } from 'vue-router'
  4. import { useTouchDevice } from '#shared/composables/useTouchDevice.ts'
  5. import CommonButton from '#desktop/components/CommonButton/CommonButton.vue'
  6. import { useUserCurrentTaskbarTabsStore } from '#desktop/entities/user/current/stores/taskbarTabs.ts'
  7. import type { UserTaskbarTabPlugin } from './types'
  8. interface Props {
  9. taskbarTabId?: ID
  10. dirty?: boolean
  11. plugin?: UserTaskbarTabPlugin
  12. }
  13. const props = defineProps<Props>()
  14. const router = useRouter()
  15. const taskbarTabStore = useUserCurrentTaskbarTabsStore()
  16. const { isTouchDevice } = useTouchDevice()
  17. const confirmRemoveUserTaskbarTab = async () => {
  18. if (!props.taskbarTabId) return
  19. if (
  20. typeof props.plugin?.confirmTabRemove === 'function' &&
  21. !(await props.plugin?.confirmTabRemove(props.dirty))
  22. )
  23. return
  24. taskbarTabStore.deleteTaskbarTab(props.taskbarTabId)
  25. // TODO: Check if the tab is the current active tab, if yes, redirect to ... ?!
  26. router.push('/dashboard')
  27. }
  28. </script>
  29. <template>
  30. <CommonButton
  31. v-if="props.taskbarTabId"
  32. v-tooltip="$t('Close this tab')"
  33. :class="{ 'opacity-0 transition-opacity': !isTouchDevice }"
  34. class="absolute end-2 top-3 focus:opacity-100 group-hover/tab:opacity-100"
  35. icon="x-lg"
  36. size="small"
  37. variant="remove"
  38. @click.stop="confirmRemoveUserTaskbarTab"
  39. />
  40. </template>
  41. <style scoped>
  42. .dragging-active button {
  43. @apply invisible;
  44. }
  45. </style>