ProfileGroups.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template lang="pug">
  2. q-page.q-py-md(:style-fn='pageStyle')
  3. .text-header {{t('profile.groups')}}
  4. .q-pa-md
  5. .text-body2 {{ t('profile.groupsInfo') }}
  6. q-list.q-mt-lg(
  7. bordered
  8. separator
  9. )
  10. q-item(
  11. v-if='state.groups.length === 0 && state.loading < 1'
  12. )
  13. q-item-section
  14. span.text-negative {{ t('profile.groupsNone') }}
  15. q-item(
  16. v-for='grp of state.groups'
  17. :key='grp.id'
  18. )
  19. q-item-section(avatar)
  20. q-avatar(
  21. color='secondary'
  22. text-color='white'
  23. icon='las la-users'
  24. rounded
  25. )
  26. q-item-section
  27. strong {{grp.name}}
  28. q-inner-loading(:showing='state.loading > 0')
  29. </template>
  30. <script setup>
  31. import gql from 'graphql-tag'
  32. import { useI18n } from 'vue-i18n'
  33. import { useMeta, useQuasar } from 'quasar'
  34. import { onMounted, reactive } from 'vue'
  35. import { useUserStore } from '@/stores/user'
  36. // QUASAR
  37. const $q = useQuasar()
  38. // STORES
  39. const userStore = useUserStore()
  40. // I18N
  41. const { t } = useI18n()
  42. // META
  43. useMeta({
  44. title: t('profile.avatar')
  45. })
  46. // DATA
  47. const state = reactive({
  48. groups: [],
  49. loading: 0
  50. })
  51. // METHODS
  52. function pageStyle (offset, height) {
  53. return {
  54. 'min-height': `${height - 100 - offset}px`
  55. }
  56. }
  57. async function fetchGroups () {
  58. state.loading++
  59. try {
  60. const respRaw = await APOLLO_CLIENT.query({
  61. query: gql`
  62. query getUserProfileGroups (
  63. $id: UUID!
  64. ) {
  65. userById (
  66. id: $id
  67. ) {
  68. id
  69. groups {
  70. id
  71. name
  72. }
  73. }
  74. }
  75. `,
  76. variables: {
  77. id: userStore.id
  78. },
  79. fetchPolicy: 'network-only'
  80. })
  81. state.groups = respRaw.data?.userById?.groups ?? []
  82. } catch (err) {
  83. $q.notify({
  84. type: 'negative',
  85. message: t('profile.groupsLoadingFailed'),
  86. caption: err.message
  87. })
  88. }
  89. state.loading--
  90. }
  91. // MOUNTED
  92. onMounted(() => {
  93. fetchGroups()
  94. })
  95. </script>