TicketLiveUsers.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, toRef } from 'vue'
  4. import CommonUserAvatar from '#shared/components/CommonUserAvatar/CommonUserAvatar.vue'
  5. import { useTicketLiveUsersDisplay } from '#shared/entities/ticket/composables/useTicketLiveUsersDisplay.ts'
  6. import type { TicketLiveAppUser } from '#shared/entities/ticket/types.ts'
  7. export interface Props {
  8. liveUserList: TicketLiveAppUser[]
  9. }
  10. const props = defineProps<Props>()
  11. const { liveUsers } = useTicketLiveUsersDisplay(toRef(props, 'liveUserList'))
  12. const LIVE_USER_LIMIT = 9
  13. const visibleLiveUsers = computed(() =>
  14. liveUsers.value.slice(0, LIVE_USER_LIMIT),
  15. )
  16. const liveUsersOverflow = computed(() => {
  17. if (liveUsers.value.length <= LIVE_USER_LIMIT) return
  18. const overflow = liveUsers.value.length - LIVE_USER_LIMIT
  19. if (overflow > 999) return '+999'
  20. return `+${overflow}`
  21. })
  22. </script>
  23. <template>
  24. <div class="flex items-center gap-2">
  25. <CommonUserAvatar
  26. v-for="liveUser in visibleLiveUsers"
  27. :key="liveUser.user.id"
  28. :entity="liveUser.user"
  29. :live="liveUser"
  30. size="small"
  31. />
  32. <div
  33. v-if="liveUsersOverflow"
  34. class="flex h-8 w-8 items-center justify-center rounded-full bg-blue-200 text-sm outline outline-1 -outline-offset-1 outline-neutral-100 dark:bg-gray-700 dark:outline-gray-900"
  35. >
  36. {{ liveUsersOverflow }}
  37. </div>
  38. </div>
  39. </template>