index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <script setup lang="ts">
  2. import { useRoute } from "vue-router";
  3. import { defineAsyncComponent, watch, onMounted } from "vue";
  4. import { storeToRefs } from "pinia";
  5. import { useUserAuthStore } from "@/stores/userAuth";
  6. import { useStationStore } from "@/stores/station";
  7. import { useTabQueryHandler } from "@/composables/useTabQueryHandler";
  8. const Queue = defineAsyncComponent(() => import("@/components/Queue.vue"));
  9. const Users = defineAsyncComponent(
  10. () => import("@/pages/Station/Sidebar/Users.vue")
  11. );
  12. const Request = defineAsyncComponent(() => import("@/components/Request.vue"));
  13. const route = useRoute();
  14. const userAuthStore = useUserAuthStore();
  15. const stationStore = useStationStore();
  16. const { tab, showTab } = useTabQueryHandler("queue");
  17. const { loggedIn } = storeToRefs(userAuthStore);
  18. const { station, userCount } = storeToRefs(stationStore);
  19. const { hasPermission } = stationStore;
  20. const canRequest = (requireLogin = true) =>
  21. station.value &&
  22. (!requireLogin || loggedIn.value) &&
  23. station.value.requests &&
  24. station.value.requests.enabled &&
  25. (station.value.requests.access === "user" ||
  26. (station.value.requests.access === "owner" &&
  27. hasPermission("stations.request")));
  28. watch(
  29. () => [station.value.requests, hasPermission("stations.request")],
  30. () => {
  31. if (tab.value === "request" && !canRequest()) showTab("queue");
  32. }
  33. );
  34. onMounted(() => {
  35. if (
  36. route.query.tab === "queue" ||
  37. route.query.tab === "users" ||
  38. route.query.tab === "request"
  39. )
  40. tab.value = route.query.tab;
  41. });
  42. </script>
  43. <template>
  44. <div class="tabs-container">
  45. <div class="tab-selection">
  46. <button
  47. class="button is-default"
  48. :class="{ selected: tab === 'queue' }"
  49. @click="showTab('queue')"
  50. >
  51. Queue
  52. </button>
  53. <button
  54. class="button is-default"
  55. :class="{ selected: tab === 'users' }"
  56. @click="showTab('users')"
  57. >
  58. Users
  59. <span class="tag">{{ Math.min(userCount, 1) }}</span>
  60. </button>
  61. <button
  62. v-if="canRequest()"
  63. class="button is-default"
  64. :class="{ selected: tab === 'request' }"
  65. @click="showTab('request')"
  66. >
  67. Request
  68. </button>
  69. <button
  70. v-else-if="canRequest(false)"
  71. class="button is-default"
  72. content="Login to request songs"
  73. v-tippy="{ theme: 'info' }"
  74. >
  75. Request
  76. </button>
  77. </div>
  78. <Queue class="tab" v-show="tab === 'queue'" @on-change-tab="showTab" />
  79. <Users class="tab" v-show="tab === 'users'" />
  80. <Request
  81. v-if="canRequest()"
  82. v-show="tab === 'request'"
  83. class="tab requests-tab"
  84. sector="station"
  85. />
  86. </div>
  87. </template>
  88. <style lang="less" scoped>
  89. .night-mode {
  90. .tab-selection .button {
  91. background: var(--dark-grey);
  92. color: var(--white);
  93. }
  94. .tab.requests-tab {
  95. background-color: var(--dark-grey-3) !important;
  96. border: 0 !important;
  97. }
  98. }
  99. .tabs-container .tab {
  100. width: 100%;
  101. height: calc(100% - 36px);
  102. position: absolute;
  103. border: 1px solid var(--light-grey-3);
  104. border-top: 0;
  105. }
  106. .tab-selection {
  107. display: flex;
  108. overflow-x: auto;
  109. .button {
  110. border-radius: @border-radius @border-radius 0 0;
  111. border: 0;
  112. text-transform: uppercase;
  113. font-size: 17px;
  114. color: var(--dark-grey-3);
  115. background-color: var(--light-grey-2);
  116. flex-grow: 1;
  117. &:not(:first-of-type) {
  118. margin-left: 5px;
  119. }
  120. }
  121. .selected {
  122. background-color: var(--primary-color) !important;
  123. color: var(--white) !important;
  124. font-weight: 600;
  125. }
  126. }
  127. :deep(.nothing-here-text) {
  128. height: 100%;
  129. }
  130. :deep(.tab) {
  131. .nothing-here-text:not(:only-child) {
  132. height: calc(100% - 40px);
  133. }
  134. &.requests-tab {
  135. background-color: var(--white);
  136. margin-bottom: 20px;
  137. border-radius: 0 0 @border-radius @border-radius;
  138. max-height: 100%;
  139. padding: 15px 10px;
  140. overflow-y: auto;
  141. .scrollable-list {
  142. padding: 10px 0;
  143. }
  144. }
  145. }
  146. :deep(.tab-actionable-button) {
  147. width: calc(100% - 20px);
  148. height: 40px;
  149. border-radius: @border-radius;
  150. margin: 10px;
  151. position: absolute;
  152. bottom: 0;
  153. border: 0;
  154. background-color: var(--primary-color) !important;
  155. color: var(--white) !important;
  156. &:active,
  157. &:focus {
  158. border: 0;
  159. }
  160. &:hover,
  161. &:focus {
  162. background-color: var(--primary-color) !important;
  163. filter: brightness(90%);
  164. }
  165. }
  166. :deep(.scrollable-list) {
  167. width: 100%;
  168. max-height: calc(100% - 40px - 20px);
  169. overflow: auto;
  170. padding: 10px;
  171. .song-item:not(:last-of-type) {
  172. margin-bottom: 10px;
  173. }
  174. }
  175. </style>