Queue.vue 7.3 KB

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