UserTaskbarTabRemove.vue 1.8 KB

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