ChooseType.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. autofocus
  20. class="
  21. bg-primary
  22. cursor-pointer
  23. flex
  24. w-full
  25. py-2
  26. px-4
  27. appearance-none
  28. "
  29. @change="updateSelectedTeam(myTeams[$event.target.value])"
  30. >
  31. <option
  32. :key="undefined"
  33. :value="undefined"
  34. hidden
  35. disabled
  36. selected
  37. >
  38. {{ $t("collection.select_team") }}
  39. </option>
  40. <option
  41. v-for="(team, index) in myTeams"
  42. :key="`team-${index}`"
  43. :value="index"
  44. >
  45. {{ team.name }}
  46. </option>
  47. </select>
  48. </div>
  49. </SmartIntersection>
  50. </SmartTab>
  51. </SmartTabs>
  52. </div>
  53. </template>
  54. <script lang="ts">
  55. import { defineComponent } from "@nuxtjs/composition-api"
  56. import gql from "graphql-tag"
  57. import { currentUserInfo$ } from "~/helpers/teams/BackendUserInfo"
  58. import { useReadonlyStream } from "~/helpers/utils/composables"
  59. export default defineComponent({
  60. props: {
  61. doc: Boolean,
  62. show: Boolean,
  63. },
  64. setup() {
  65. return {
  66. currentUser: useReadonlyStream(currentUserInfo$, null),
  67. }
  68. },
  69. data() {
  70. return {
  71. skipTeamsFetching: true,
  72. }
  73. },
  74. apollo: {
  75. myTeams: {
  76. query: gql`
  77. query GetMyTeams {
  78. myTeams {
  79. id
  80. name
  81. myRole
  82. }
  83. }
  84. `,
  85. pollInterval: 10000,
  86. skip() {
  87. return this.skipTeamsFetching
  88. },
  89. },
  90. },
  91. methods: {
  92. onTeamSelectIntersect() {
  93. // Load team data as soon as intersection
  94. this.$apollo.queries.myTeams.refetch()
  95. this.skipTeamsFetching = false
  96. },
  97. updateCollectionsType(tabID: string) {
  98. this.$emit("update-collection-type", tabID)
  99. },
  100. updateSelectedTeam(team: any) {
  101. this.$emit("update-selected-team", team)
  102. },
  103. },
  104. })
  105. </script>