ChooseType.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div v-if="show">
  3. <SmartTabs :id="'collections_tab'" @tab-changed="updateCollectionsType">
  4. <SmartTab
  5. :id="'my-collections'"
  6. :label="$t('collection.my_collections')"
  7. :selected="true"
  8. />
  9. <SmartTab
  10. v-if="currentUser && currentUser.eaInvited && !doc"
  11. :id="'team-collections'"
  12. :label="$t('collection.team_collections')"
  13. >
  14. <SmartIntersection @intersecting="onTeamSelectIntersect">
  15. <div class="select-wrapper">
  16. <select
  17. id="team"
  18. type="text"
  19. autocomplete="off"
  20. autofocus
  21. class="
  22. bg-transparent
  23. border-t border-dividerLight
  24. cursor-pointer
  25. flex
  26. font-medium
  27. w-full
  28. py-2
  29. px-4
  30. appearance-none
  31. hover:bg-primaryDark
  32. "
  33. @change="updateSelectedTeam(myTeams[$event.target.value])"
  34. >
  35. <option
  36. :key="undefined"
  37. :value="undefined"
  38. hidden
  39. disabled
  40. selected
  41. >
  42. {{ $t("collection.select_team") }}
  43. </option>
  44. <option
  45. v-for="(team, index) in myTeams"
  46. :key="`team-${index}`"
  47. :value="index"
  48. >
  49. {{ team.name }}
  50. </option>
  51. </select>
  52. </div>
  53. </SmartIntersection>
  54. </SmartTab>
  55. </SmartTabs>
  56. </div>
  57. </template>
  58. <script lang="ts">
  59. import { defineComponent } from "@nuxtjs/composition-api"
  60. import gql from "graphql-tag"
  61. import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
  62. import { useReadonlyStream } from "~/helpers/utils/composables"
  63. export default defineComponent({
  64. props: {
  65. doc: Boolean,
  66. show: Boolean,
  67. },
  68. setup() {
  69. return {
  70. currentUser: useReadonlyStream(currentUserInfo$, null),
  71. }
  72. },
  73. data() {
  74. return {
  75. skipTeamsFetching: true,
  76. }
  77. },
  78. apollo: {
  79. myTeams: {
  80. query: gql`
  81. query GetMyTeams {
  82. myTeams {
  83. id
  84. name
  85. myRole
  86. }
  87. }
  88. `,
  89. pollInterval: 10000,
  90. skip() {
  91. return this.skipTeamsFetching
  92. },
  93. },
  94. },
  95. methods: {
  96. onTeamSelectIntersect() {
  97. // Load team data as soon as intersection
  98. this.$apollo.queries.myTeams.refetch()
  99. this.skipTeamsFetching = false
  100. },
  101. updateCollectionsType(tabID: string) {
  102. this.$emit("update-collection-type", tabID)
  103. },
  104. updateSelectedTeam(team: any) {
  105. this.$emit("update-selected-team", team)
  106. },
  107. },
  108. })
  109. </script>