Queue.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div id="queue">
  3. <draggable
  4. :class="{
  5. 'actionable-button-hidden': !actionableButtonVisible,
  6. 'scrollable-list': true
  7. }"
  8. v-if="queue.length > 0"
  9. v-model="queue"
  10. v-bind="dragOptions"
  11. @start="drag = true"
  12. @end="drag = false"
  13. @change="repositionSongInQueue"
  14. >
  15. <transition-group
  16. type="transition"
  17. :name="!drag ? 'draggable-list-transition' : null"
  18. >
  19. <song-item
  20. v-for="(song, index) in queue"
  21. :key="index + song.youtubeId"
  22. :song="song"
  23. :requested-by="
  24. station.type === 'community' &&
  25. station.partyMode === true
  26. "
  27. :class="{
  28. 'item-draggable': isAdminOnly() || isOwnerOnly()
  29. }"
  30. >
  31. <div
  32. v-if="isAdminOnly() || isOwnerOnly()"
  33. class="song-actions"
  34. slot="actions"
  35. >
  36. <confirm
  37. v-if="isOwnerOnly() || isAdminOnly()"
  38. placement="left"
  39. @confirm="removeFromQueue(song.youtubeId)"
  40. >
  41. <i
  42. class="material-icons delete-icon"
  43. content="Remove Song from Queue"
  44. v-tippy
  45. >delete_forever</i
  46. >
  47. </confirm>
  48. <i
  49. class="material-icons"
  50. v-if="index > 0"
  51. @click="moveSongToTop(song, index)"
  52. content="Move to top of Queue"
  53. v-tippy
  54. >vertical_align_top</i
  55. >
  56. <i
  57. v-if="queue.length - 1 !== index"
  58. @click="moveSongToBottom(song, index)"
  59. class="material-icons"
  60. content="Move to bottom of Queue"
  61. v-tippy
  62. >vertical_align_bottom</i
  63. >
  64. </div>
  65. </song-item>
  66. </transition-group>
  67. </draggable>
  68. <p class="nothing-here-text" v-else>
  69. There are no songs currently queued
  70. </p>
  71. <button
  72. class="button is-primary tab-actionable-button"
  73. v-if="
  74. loggedIn &&
  75. station.type === 'community' &&
  76. station.partyMode &&
  77. ((station.locked && isOwnerOnly()) ||
  78. !station.locked ||
  79. (station.locked && isAdminOnly() && dismissedWarning))
  80. "
  81. @click="
  82. openModal({
  83. sector: 'station',
  84. modal: 'addSongToQueue'
  85. })
  86. "
  87. >
  88. <i class="material-icons icon-with-button">queue</i>
  89. <span class="optional-desktop-only-text"> Add Song To Queue </span>
  90. </button>
  91. <button
  92. class="button is-primary tab-actionable-button"
  93. v-if="loggedIn && station.type === 'official'"
  94. @click="
  95. openModal({
  96. sector: 'station',
  97. modal: 'requestSong'
  98. })
  99. "
  100. >
  101. <i class="material-icons icon-with-button">queue</i>
  102. <span class="optional-desktop-only-text"> Request Song </span>
  103. </button>
  104. <button
  105. class="button is-primary tab-actionable-button disabled"
  106. v-if="
  107. !loggedIn &&
  108. ((station.type === 'community' &&
  109. station.partyMode &&
  110. !station.locked) ||
  111. station.type === 'official')
  112. "
  113. content="Login to add songs to queue"
  114. v-tippy
  115. >
  116. <i class="material-icons icon-with-button">queue</i>
  117. <span class="optional-desktop-only-text"> Add Song To Queue </span>
  118. </button>
  119. <div
  120. id="queue-locked"
  121. v-if="station.type === 'community' && station.locked"
  122. >
  123. <button
  124. v-if="isAdminOnly() && !isOwnerOnly() && !dismissedWarning"
  125. class="button tab-actionable-button"
  126. @click="dismissedWarning = true"
  127. >
  128. THIS STATION'S QUEUE IS LOCKED.
  129. </button>
  130. <button
  131. v-if="!isAdminOnly() && !isOwnerOnly()"
  132. class="button tab-actionable-button"
  133. >
  134. THIS STATION'S QUEUE IS LOCKED.
  135. </button>
  136. </div>
  137. </div>
  138. </template>
  139. <script>
  140. import { mapActions, mapState, mapGetters } from "vuex";
  141. import draggable from "vuedraggable";
  142. import Toast from "toasters";
  143. import SongItem from "@/components/SongItem.vue";
  144. import Confirm from "@/components/Confirm.vue";
  145. export default {
  146. components: { draggable, SongItem, Confirm },
  147. data() {
  148. return {
  149. dismissedWarning: false,
  150. actionableButtonVisible: false,
  151. drag: false
  152. };
  153. },
  154. computed: {
  155. queue: {
  156. get() {
  157. return this.$store.state.station.songsList;
  158. },
  159. set(queue) {
  160. this.$store.commit("station/updateSongsList", queue);
  161. }
  162. },
  163. dragOptions() {
  164. return {
  165. animation: 200,
  166. group: "queue",
  167. disabled: !(this.isAdminOnly() || this.isOwnerOnly()),
  168. ghostClass: "draggable-list-ghost"
  169. };
  170. },
  171. ...mapState({
  172. loggedIn: state => state.user.auth.loggedIn,
  173. userId: state => state.user.auth.userId,
  174. userRole: state => state.user.auth.role,
  175. station: state => state.station.station,
  176. songsList: state => state.station.songsList,
  177. noSong: state => state.station.noSong
  178. }),
  179. ...mapGetters({
  180. socket: "websockets/getSocket"
  181. })
  182. },
  183. updated() {
  184. // check if actionable button is visible, if not: set max-height of queue items to 100%
  185. if (
  186. document
  187. .getElementById("queue")
  188. .querySelectorAll(".tab-actionable-button").length > 0
  189. )
  190. this.actionableButtonVisible = true;
  191. else this.actionableButtonVisible = false;
  192. },
  193. methods: {
  194. isOwnerOnly() {
  195. return this.loggedIn && this.userId === this.station.owner;
  196. },
  197. isAdminOnly() {
  198. return this.loggedIn && this.userRole === "admin";
  199. },
  200. removeFromQueue(youtubeId) {
  201. this.socket.dispatch(
  202. "stations.removeFromQueue",
  203. this.station._id,
  204. youtubeId,
  205. res => {
  206. if (res.status === "success") {
  207. new Toast("Successfully removed song from the queue.");
  208. } else new Toast(res.message);
  209. }
  210. );
  211. },
  212. repositionSongInQueue({ moved }) {
  213. if (!moved) return; // we only need to update when song is moved
  214. this.socket.dispatch(
  215. "stations.repositionSongInQueue",
  216. {
  217. ...moved.element,
  218. oldIndex: moved.oldIndex,
  219. newIndex: moved.newIndex
  220. },
  221. this.station._id,
  222. res => {
  223. new Toast({ content: res.message, timeout: 4000 });
  224. }
  225. );
  226. },
  227. moveSongToTop(song, index) {
  228. this.repositionSongInQueue({
  229. moved: {
  230. element: song,
  231. oldIndex: index,
  232. newIndex: 0
  233. }
  234. });
  235. },
  236. moveSongToBottom(song, index) {
  237. this.repositionSongInQueue({
  238. moved: {
  239. element: song,
  240. oldIndex: index,
  241. newIndex: this.songsList.length
  242. }
  243. });
  244. },
  245. ...mapActions("modalVisibility", ["openModal"])
  246. }
  247. };
  248. </script>
  249. <style lang="scss" scoped>
  250. .night-mode {
  251. #queue {
  252. background-color: var(--dark-grey-3) !important;
  253. border: 0 !important;
  254. }
  255. }
  256. #queue {
  257. background-color: var(--white);
  258. border-radius: 0 0 5px 5px;
  259. .actionable-button-hidden {
  260. max-height: 100%;
  261. }
  262. .song-item:not(:last-of-type) {
  263. margin-bottom: 10px;
  264. }
  265. #queue-locked {
  266. display: flex;
  267. justify-content: center;
  268. }
  269. button.disabled {
  270. filter: grayscale(0.4);
  271. }
  272. }
  273. </style>