index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <script setup lang="ts">
  2. import { useStore } from "vuex";
  3. import { useRoute } from "vue-router";
  4. import { defineAsyncComponent, computed, watch, onMounted } from "vue";
  5. import useTabQueryHandler from "@/composables/useTabQueryHandler";
  6. const Queue = defineAsyncComponent(() => import("@/components/Queue.vue"));
  7. const Users = defineAsyncComponent(
  8. () => import("@/pages/Station/Sidebar/Users.vue")
  9. );
  10. const Request = defineAsyncComponent(() => import("@/components/Request.vue"));
  11. const store = useStore();
  12. const route = useRoute();
  13. const { tab, showTab } = useTabQueryHandler("queue");
  14. const station = computed(() => store.state.station.station);
  15. const userId = computed(() => store.state.user.auth.userId);
  16. const loggedIn = computed(() => store.state.user.auth.loggedIn);
  17. const role = computed(() => store.state.user.auth.rol);
  18. const isOwner = () =>
  19. loggedIn.value && station.value && userId.value === station.value.owner;
  20. const isAdmin = () => loggedIn.value && role.value === "admin";
  21. const isOwnerOrAdmin = () => isOwner() || isAdmin();
  22. const canRequest = (requireLogin = true) =>
  23. station.value &&
  24. (!requireLogin || loggedIn.value) &&
  25. station.value.requests &&
  26. station.value.requests.enabled &&
  27. (station.value.requests.access === "user" ||
  28. (station.value.requests.access === "owner" && isOwnerOrAdmin()));
  29. watch(
  30. () => station.value.requests,
  31. () => {
  32. if (tab.value === "request" && !canRequest()) showTab("queue");
  33. }
  34. );
  35. onMounted(() => {
  36. if (
  37. route.query.tab === "queue" ||
  38. route.query.tab === "users" ||
  39. route.query.tab === "request"
  40. )
  41. tab.value = route.query.tab;
  42. });
  43. </script>
  44. <template>
  45. <div id="tabs-container">
  46. <div id="tab-selection">
  47. <button
  48. class="button is-default"
  49. :class="{ selected: tab === 'queue' }"
  50. @click="showTab('queue')"
  51. >
  52. Queue
  53. </button>
  54. <button
  55. class="button is-default"
  56. :class="{ selected: tab === 'users' }"
  57. @click="showTab('users')"
  58. >
  59. Users
  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'" />
  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>