Queue.vue 7.5 KB

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