Queue.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. sector === 'station' &&
  75. loggedIn &&
  76. station.type === 'community' &&
  77. station.partyMode &&
  78. ((station.locked && isOwnerOnly()) ||
  79. !station.locked ||
  80. (station.locked && isAdminOnly() && dismissedWarning))
  81. "
  82. @click="openModal('manageStation')"
  83. >
  84. <i class="material-icons icon-with-button">queue</i>
  85. <span class="optional-desktop-only-text"> Add Song To Queue </span>
  86. </button>
  87. <button
  88. class="button is-primary tab-actionable-button"
  89. v-if="
  90. sector === 'station' && loggedIn && station.type === 'official'
  91. "
  92. @click="openModal('requestSong')"
  93. >
  94. <i class="material-icons icon-with-button">queue</i>
  95. <span class="optional-desktop-only-text"> Request Song </span>
  96. </button>
  97. <button
  98. class="button is-primary tab-actionable-button disabled"
  99. v-if="
  100. sector === 'station' &&
  101. !loggedIn &&
  102. ((station.type === 'community' &&
  103. station.partyMode &&
  104. !station.locked) ||
  105. station.type === 'official')
  106. "
  107. content="Login to add songs to queue"
  108. v-tippy
  109. >
  110. <i class="material-icons icon-with-button">queue</i>
  111. <span class="optional-desktop-only-text"> Add Song To Queue </span>
  112. </button>
  113. <div
  114. id="queue-locked"
  115. v-if="station.type === 'community' && station.locked"
  116. >
  117. <button
  118. v-if="isAdminOnly() && !isOwnerOnly() && !dismissedWarning"
  119. class="button tab-actionable-button"
  120. @click="dismissedWarning = true"
  121. >
  122. THIS STATION'S QUEUE IS LOCKED.
  123. </button>
  124. <button
  125. v-if="!isAdminOnly() && !isOwnerOnly()"
  126. class="button tab-actionable-button"
  127. >
  128. THIS STATION'S QUEUE IS LOCKED.
  129. </button>
  130. </div>
  131. </div>
  132. </template>
  133. <script>
  134. import { mapActions, mapState, mapGetters } from "vuex";
  135. import draggable from "vuedraggable";
  136. import Toast from "toasters";
  137. import SongItem from "@/components/SongItem.vue";
  138. import Confirm from "@/components/Confirm.vue";
  139. export default {
  140. components: { draggable, SongItem, Confirm },
  141. props: {
  142. sector: {
  143. type: String,
  144. default: "station"
  145. }
  146. },
  147. data() {
  148. return {
  149. dismissedWarning: false,
  150. actionableButtonVisible: false,
  151. drag: false
  152. };
  153. },
  154. computed: {
  155. queue: {
  156. get() {
  157. if (this.sector === "manageStation") {
  158. return this.$store.state.modals.manageStation.songsList;
  159. }
  160. return this.$store.state.station.songsList;
  161. },
  162. set(queue) {
  163. if (this.sector === "manageStation") {
  164. this.$store.commit(
  165. "modals/manageStation/updateSongsList",
  166. queue
  167. );
  168. } else {
  169. this.$store.commit("station/updateSongsList", queue);
  170. }
  171. }
  172. },
  173. dragOptions() {
  174. return {
  175. animation: 200,
  176. group: "queue",
  177. disabled: !(this.isAdminOnly() || this.isOwnerOnly()),
  178. ghostClass: "draggable-list-ghost"
  179. };
  180. },
  181. ...mapState({
  182. loggedIn: state => state.user.auth.loggedIn,
  183. userId: state => state.user.auth.userId,
  184. userRole: state => state.user.auth.role,
  185. station: state => state.station.station,
  186. songsList: state => state.station.songsList,
  187. otherSongsList: state => state.modals.manageStation.songsList,
  188. noSong: state => state.station.noSong
  189. }),
  190. ...mapGetters({
  191. socket: "websockets/getSocket"
  192. })
  193. },
  194. updated() {
  195. // check if actionable button is visible, if not: set max-height of queue items to 100%
  196. if (
  197. document
  198. .getElementById("queue")
  199. .querySelectorAll(".tab-actionable-button").length > 0
  200. )
  201. this.actionableButtonVisible = true;
  202. else this.actionableButtonVisible = false;
  203. },
  204. methods: {
  205. isOwnerOnly() {
  206. return this.loggedIn && this.userId === this.station.owner;
  207. },
  208. isAdminOnly() {
  209. return this.loggedIn && this.userRole === "admin";
  210. },
  211. removeFromQueue(youtubeId) {
  212. this.socket.dispatch(
  213. "stations.removeFromQueue",
  214. this.station._id,
  215. youtubeId,
  216. res => {
  217. if (res.status === "success") {
  218. new Toast("Successfully removed song from the queue.");
  219. } else new Toast(res.message);
  220. }
  221. );
  222. },
  223. repositionSongInQueue({ moved }) {
  224. if (!moved) return; // we only need to update when song is moved
  225. this.socket.dispatch(
  226. "stations.repositionSongInQueue",
  227. {
  228. ...moved.element,
  229. oldIndex: moved.oldIndex,
  230. newIndex: moved.newIndex
  231. },
  232. this.station._id,
  233. res => {
  234. new Toast({ content: res.message, timeout: 4000 });
  235. }
  236. );
  237. },
  238. moveSongToTop(song, index) {
  239. this.repositionSongInQueue({
  240. moved: {
  241. element: song,
  242. oldIndex: index,
  243. newIndex: 0
  244. }
  245. });
  246. },
  247. moveSongToBottom(song, index) {
  248. this.repositionSongInQueue({
  249. moved: {
  250. element: song,
  251. oldIndex: index,
  252. newIndex: this.songsList.length
  253. }
  254. });
  255. },
  256. ...mapActions("modalVisibility", ["openModal"])
  257. }
  258. };
  259. </script>
  260. <style lang="scss" scoped>
  261. .night-mode {
  262. #queue {
  263. background-color: var(--dark-grey-3) !important;
  264. border: 0 !important;
  265. }
  266. }
  267. #queue {
  268. background-color: var(--white);
  269. border-radius: 0 0 5px 5px;
  270. .actionable-button-hidden {
  271. max-height: 100%;
  272. }
  273. .song-item:not(:last-of-type) {
  274. margin-bottom: 10px;
  275. }
  276. #queue-locked {
  277. display: flex;
  278. justify-content: center;
  279. }
  280. button.disabled {
  281. filter: grayscale(0.4);
  282. }
  283. }
  284. </style>